Install all all necessary packages:

sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules

Open your postfix config file:

sudo nano /etc/postfix/main.cf

Add the following lines (there might allready be a empty “relayhost” line):

relayhost = [smtp.example.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

Open:

sudo nano /etc/postfix/sasl_passwd

Add:

[smtp.example.com]:587    USERNAME@example.com:PASSWORD

Change permission and update postfix config to use sasl_passwd file:

sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

Reload postfix config:

sudo /etc/init.d/postfix reload

The following command should send an Email if you have done everything right:

echo "Test" | mail -s "Test" example@example.com
⤧  Next post Automatic Minecraft server update ⤧  Previous post Let Ubuntu send you Emails if security updates are available