I followed two nearly-identical guides:
Basically, you need to install the ssmtp package, then edit the ssmtp.conf configuration file:
sudo apt-get install ssmtp
# Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. #root=postmaster root=MyEmailAddress@gmail.com # The place where the mail goes. The actual machine name is required no # MX records are consulted. Commonly mailhosts are named mail.domain.com #mailhub=mail mailhub=smtp.gmail.com:587 AuthUser=MyEmailAddress@gmail.com AuthPass=MyPassword UseTLS=YES UseSTARTTLS=YES # Where will the mail seem to come from? #rewriteDomain= rewriteDomain=gmail.com # The full hostname #hostname=MyMediaServer.home hostname=MyEmailAddress@gmail.com # Are users allowed to set their own From: address? # YES - Allow the user to specify their own From: address # NO - Use the system generated From: address FromLineOverride=YES
If you have two-factor (2FA) authentication set up for your Google account, you need to create an "app password" for this "device". Visit this page to create an app password that doesn't use 2FA auth: https://myaccount.google.com/apppasswords
However, there is a problem with those two guides, specifically in the hostname= line. If you put your actual email address as the hostname entry, then google will complain when you try to connect. You can use this test command to see what is going on:
$ echo "Hello 1" | sudo ssmtp -vvv firstname.lastname@example.org [< -] 220 smtp.gmail.com ESMTP j76sm1853421ioi.14 - gsmtp [->] EHLO MyEmailAddress@gmail.com [< -] 501 5.5.4 https://support.google.com/mail/?p=helo j76sm1853421ioi.14 - gsmtp ssmtp: Cannot open smtp.gmail.com:587
What you need to do is to set hostname=localhost in the ssmtp.conf file. Then it should work fine.