Install Postfix
sudo apt-get install postfix mailutils
Internet Site
[default]
Add Gmail Username and Password
sudo vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 [email protected]:password
Secure
sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
Configure the Postfix Relay Server
sudo vi /etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
Restart Postfix
sudo systemctl enable postfix
sudo systemctl restart postfix
Test Postfix
mail -s "Test mail" [email protected] <<< "A test message"
Reference