Email for Linux Hosts
Updated on 21 Jun 2025.
I wanted my containers / VMs to be able to send emails out to me so that when I installed more complex applications or solutions on top of these platforms, they would be able to provide important feedback.
After doing some tinkering around with OpenSMTPD and not getting it work as I wanted to, I got Postfix working. So this section provides a summary of how I achieved this.
Postfix relay to Gmail
Reference URL:
Install and Configure Postfix
$ sudo apt install mailutils libsasl2-modules
to install Postfix
Edit the /etc/postfix/main.cf
configuration file and set the following:
myhostname = mail.thomas-pk.com
mynetworks = 127.0.0.1
or192.168.1.0/24
depending on whether this server will only send out going mail or it works as an smtp relay.
Configure you GMail App Password
Create the /etc/postfix/sasl/sasl_password
file, as follows:
[smtp.gmail.com]:587 yourid@gmail.com:app_password
Then, create a hash map of the password file. This generates the sasl_password.db
file.
Then, update the permission so that only root can view or change it with
$ sudo chmod 0600 /etc/postfix/sasl/sasl_password*
Configure Postfix to use GMail
Edit the /etc/postfix/main.cf
configuration file and set the following:
relayhost=[smtp.gmail.com]:587
smtp_sasl_auth_enable=yes
smtp_sasl_security_options=noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_password
Getting ready for the test
In a seperate window, start monitoring the smtp logs with $ sudo journalctl -f _COMM=smtp