Postfix/Fail2ban, Send mail to admin on problems

I would like for Postfix if possible, or Fail2ban if possible (without banning) to send a notification email to root or an admin account with the logline when something wrongs happens when sending an email.

Example lines I would like notifications on:

  • TLS is required, but was not offered by host hotmail-com.olc.protection.outlook.com
  • said: 550 5.7.1 Unfortunately, messages from [Email server IP] weren't sent. Please contact your Internet service provider since part of their network is on our block list (This was resolved)

You outline a positive list of things you want to hear about, but what is often much more helpful is to maintain a negative list of things you do not want to hear about and receive at least aggregate notifications about all non-excluded logs.

E.g. if you were only watching things going wrong in TLS-establishing or EOD stage, you might never learn about some problems that occur before either, such as routing problems in only one of the two currently used IP versions.

The basic approach would be to continuously scan journal/logs for entries not known to be benign or otherwise uninteresting:

journalctl -u postfix@- -u opendmarc -o short-iso-precise -f | grep -v -E -f mail.pcre | notify.sh

Existing solutions that follow this apporach include the program logwatch.


Note that you likely also want to work on the feedback channels your users have available to contact an appropriate postmaster role. After all, most problems that could appear in postfix logs already do notify someone - at minimum, the sender of the message ("bounce").