Postfix search mail log
The joys of debugging email issues!
To search the postfix mail log, you can use the postlog
command or grep
command with the log file path. Here are a few examples:
Using postlog
command:
- Install the
postlog
package if you haven't already:sudo apt-get install postlog
(on Ubuntu-based systems) - Run the following command to search for a specific message ID:
postlog -s <message_id>
- Run the following command to search for a specific sender or recipient:
postlog -s -s <sender_email> -r <recipient_email>
Using grep
command:
- Find the log file path: usually located at
/var/log/mail.log
or/var/log/mail.log.1
(depending on the system and log rotation settings) - Run the following command to search for a specific message ID:
grep "message-id: <message_id>" /var/log/mail.log
- Run the following command to search for a specific sender or recipient:
grep "<sender_email>" /var/log/mail.log
orgrep "<recipient_email>" /var/log/mail.log
Tips and variations:
- Use the
-i
flag withgrep
to perform a case-insensitive search:grep -i "<sender_email>" /var/log/mail.log
- Use the
-r
flag withgrep
to search recursively through multiple log files:grep -r "<sender_email>" /var/log/mail.log*
- Use the
less
command to view the log file and search for specific patterns:less /var/log/mail.log | grep "<sender_email>"
- Use the
tail
command to view the last few lines of the log file and search for specific patterns:tail -f /var/log/mail.log | grep "<sender_email>"
Remember to replace <message_id>
, <sender_email>
, and <recipient_email>
with the actual values you're searching for.