Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have received a letter from my hoster, that my server sends a lot of emails.

It's strange.

How can I enable logging of emails? Or just of to headers.

Ubuntu 12.04, postfix.

share|improve this question
I'm curious as to what you search for yourself. The first hit on Google using mail log ubuntu highlights the location of the log. – gertvdijk Jan 20 '13 at 10:39
The problem is I want to see subjects. – DmitryR Jan 20 '13 at 11:20
I've added subject logging to my answer. Next time put this into your question, as this is not trivial and a very important aspect. (see my answer for why this isn't trivial) – gertvdijk Jan 20 '13 at 13:41
up vote 8 down vote accepted

Logging is enabled by default

See /var/log/mail.log:

Jan 20 06:47:57 zarafa postfix/qmgr[1021]: A1749428: from=<>, size=2110, nrcpt=1 (queue active)
Jan 20 06:47:57 zarafa postfix/smtpd[21751]: disconnect from[]
Jan 20 06:47:58 zarafa postfix/lmtp[21756]: A1749428: to=<>, orig_to=<>, relay=localhost[]:2003, delay=0.5, delays=0.15/0.01/0.08/0.26, dsn=2.1.5, status=sent (250 2.1.5 Ok)
Jan 20 06:47:58 zarafa postfix/qmgr[1021]: A1749428: removed

Be careful about mail servers becoming an open mail relay due to a configuration change, as you probably don't intend to run one. Because, if it is, then your server is a very easy target for spammers to abuse your mail server.

Subject logging

In the comments your question changed to how to enable logging of the subject. One important note here is that Postfix is an MTA (Mail Transport Agent) and it's not responsibility of an MTA to do stuff with the contents of mails. It's simply only concerned about the headers for transport primarily.

However, with Postfix as an MTA you're lucky as it does have a feature to help you out. It's possible to log based on a regular expression to match on the headers using this method:

  1. Install the package postfix-pcre.

  2. Create a file with the regular expression to match, e.g. /etc/postfix/header_checks:

    /^Subject:/ INFO
  3. In your /etc/postfix/ add this to your configuration with a line like this:

    header_checks = pcre:/etc/postfix/header_checks
  4. Reload the configuration:

    sudo service postfix reload
  5. View the logs:

    Jan 20 13:50:01 zarafa postfix/cleanup[1416]: 74D321034: info: header Subject: testsubject from localhost[]; from=<> to=<> proto=ESMTP helo=<zarafa>

For more content-based inspection, see the manpage about header_checks(5).

share|improve this answer
Do you know how can I enable subject header logging? – DmitryR Jan 20 '13 at 11:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.