How To Log Subject Lines in Postfix

December 10, 2009 by David · Leave a Comment 

By default, Postfix doesn’t log the subject lines of emails that it handles. There’s nothing wrong with this, however sometimes a user will want to know if an email came in (or was sent), and you’ll almost never have the message ID on hand to search for.

Luckily, Postfix does allow you to log warning messages for subject lines, and so we’ll use this to simply log a warning message for any subject line. It’s a bit of a ‘hack’, but works and doesn’t cause any problems (Postfix doesn’t block or alter the emails).

Firstly, edit the main.cf file and add the following line:

header_checks = regexp:/etc/postfix/header_checks

Next, create the /etc/postfix/header_checks file and add the following line:

/^subject:/ WARN

Reload/restart Postfix and send a test message. You’ll see something like the following in your logs:

Dec 10 10:57:01 localhost postfix/cleanup[22492]: 2290326720: warning: header subject: test email from localhost[127.0.0.1]; from= to= proto=SMTP helo=

Notice the “warning: header subject” bit. Now, every subject line will be logged :) It makes life a lot easier when doing email troubleshooting on a mail server.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!