Skip to main content Logo (IEC resistor symbol) logo

Quis custodiet ipsos custodes?
Home | About | All pages | RSS Feed | Gopher

Postfix: log message from, to and subject

Published: 28-03-2009 | Author: 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.

If you like this article, consider sponsoring me by trying out a Digital Ocean VPS. With this link you'll get $100 credit for 60 days). (referral link)

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:

service 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