Setting up ssmtp (using a Gmail account) on Ubuntu/Linux
Since I have 2-factor authentication turned on for Gmail in order to get my Gmail account set up in ssmtp I had to set up an App Password. Below is a link to Google on how to do that, but I also listed the steps out. You will need to securely save that App Password. I will use APP_PASSWORD as a placeholder in the code, you need to replace that with your actual App Password.
Also, email isn't required so you can skip this step if you aren't comfortable with an App Password.
Reference: https://support.google.com/mail/answer/185833
- Goto your Google Account: https://myaccount.google.com/.
- Select Security.
- Under "Signing in to Google," select App Passwords. You may need to sign in. If you don’t have this option, it might be because:
- 2-Step Verification is not set up for your account.
- 2-Step Verification is only set up for security keys.
- Your account is through work, school, or other organization.
- You turned on Advanced Protection.
- At the bottom, choose Select app and choose the app you are using and then Select device and choose the device you’re using and then Generate.
- Follow the instructions to enter the App Password. The App Password is the 16-character code in the yellow bar on your device.
- Tap Done.
Now let's edit the ssmtp configuration file and add your Gmail details:
sudo nano /etc/ssmtp/ssmtp.conf
Change the root to your email address, change the mailhub to Gmail, and change the hostname to your computer.
root=username@gmail.com
mailhub=smtp.gmail.com:465
hostname=mycomputer
Finally, at the bottom of the configuration file, add the following lines. Be sure to update the
AuthPass
with your App Password from Google.
AuthUser=username@gmail.com
AuthPass=APP_PASSWORD
UseTLS=YES
Let's send a test email and make sure it works. Replace username@gmail.com with your email address.
printf "Subject: Testing SMTP Email\n\nThis is a test email." | /usr/sbin/ssmtp username@gmail.com
You should have received an email in your Gmail inbox.