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

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/header_checks 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]>

SUBSCRIBE FOR NEW ARTICLES

@
comments powered by Disqus