Logwatch with postfix and mailgun

Install postfix and logwatch

sudo apt install postfix logwatch

Add Mailgun stmp login and password to /etc/postfix/sasl_passwd

[smtp.mailgun.org]:587 username@mydomain.com:PASSWORD

Update postfix lookup table.

sudo postmap /etc/postfix/sasl_passwd

Make files readable by only root.

sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

Add these lines to /etc/postfix/main.cf

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

relayhost = [smtp.mailgun.org]:587

Create a cron job /etc/cron.daily/00logwatch to email logwatch report.

/usr/sbin/logwatch --mailto myemail@example.com --detail high

References: