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

myhostname = mydomain.com
# enable SASL authentication
smtp_sasl_auth_enable = yes
# disallow methods that allow anonymous authentication.
smtp_sasl_security_options = noanonymous
# where to find sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# Enable STARTTLS encryption
smtp_use_tls = yes
# where to find CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

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