An easy way to send emails from an Ubuntu machine for things such as system alerts is by using SSMTP.
Install and configure SSMTP
Start by installing the ssmtp package by running:
sudo apt-get install ssmtp
Once complete, edit the configuration file by located at
/etc/ssmtp/ssmtp.conf (I use nano as my editor):
sudo nano /etc/ssmtp/ssmtp.conf
Edit the field that states
# root is the person who gets all mail for userids < 1000 root=ADD_YOUR_EMAIL_HERE
so that you can receive the emails and add the following information to the bottom of the file (editing the AuthUser and AuthPass):
# Gmail Information mailhub=smtp.gmail.com:587 AuthUser=YOUR_EMAIL AuthPass=YOUR_PASSWORD UseTLS=YES UseSTARTTLS=YES
Time to test
Now it’s time to test and make sure everything works. Run the following command making sure to edit the email field to match your information:
echo "Test message from Linux server using ssmtp" | sudo ssmtp -vvv [email protected]
You should now receive an email from your server. If so, you have successfully configured your server to send emails using SSMTP!