Postfix - how log email headers like From, To and Subject

This is a little trick for Postfix, it lets you log the subject, from and to of all the emails postfix sends (or which pass through it if you run it as a relay). It comes in handy when you need to debug an email issue and need to confirm your mailserver has sent the message.

First create the file _/etc/postfix/headerchecks and insert this into it:

/^subject:/      WARN
/^to:/           WARN
/^from:/         WARN
/^Subject:/      WARN
/^To:/           WARN
/^From:/         WARN

Now, in your postfix /etc/postfix/main.cf add the following to the end of the file:

header_checks = regexp:/etc/postfix/header_checks

And restart postfix:

/etc/init.d/postfix restart

You will hopefully now get log items like below, and if not you have a problem with your mailserver:

Mar  6 09:10:46 mailsever postfix/cleanup[23094]: 44DmfZ2x2nz6tsC: warning: header To: "recipient@example.com" <recipient@example.com> from unknown[192.168.0.208]; from=<sender@example.com> to=<recipient@example.com> proto=ESMTP helo=<[192.168.0.208]>
Mar  6 09:10:46 mailsever postfix/cleanup[23094]: 44DmfZ2x2nz6tsC: warning: header From: Sender <sender@example.com> from unknown[192.168.0.208]; from=<sender@example.com> to=<recipient@example.com> proto=ESMTP helo=<[192.168.0.208]>
Mar  6 09:10:46 mailsever postfix/cleanup[23094]: 44DmfZ2x2nz6tsC: warning: header Subject: example subject from unknown[192.168.0.208]; from=<sender@example.com> to=<recipient@example.com> proto=ESMTP helo=<[192.168.0.208]>

Posftix regular expression support

You almost install regexp support package for postfix. Like apt-get install postfix-pcre in debian based distros.

Share Comments
comments powered by Disqus