Skip to main content

Postfix: log message from, to and subject

28-03-2009 | Remy van Elst | Text only version of this article

Table of Contents

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/ 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:

Dec  4 08:23:05 localhost postfix/cleanup[2278]: 90CA714: warning: header Subject: This is a testmail which gets logged from localhost[]; from=<root@localhost> to=<root@localhost> proto=ESMTP helo=<localhost>

Tags: logging  mail  mta  postfix  tutorials