The 3 most common usages of e-mail in a virtual server in the cloud can be defined by the necessities of the service:

  • SMTP Relay: The applications need to send emails for notifications, password resets, and so on, but there is no need for a full email server with domain and user accounts. The SMTP will serve the applications by relaying to an external SMTP server.
    • This is the case covered by the example in this post.
  • SMTP Server: The applications need to send emails for notifications, password resets, and so on. The email server of the domain is external, and this server will also send emails for that domain. The SMTP will serve the applications as an SMTP server.
  • E-Mail Server: The server is the email server of a domain and needs to have accounts, SMTP, and serve both local and external applications.

Using SSMTP with Google SMTP Relay:

The easiest and perhaps most popular option is the SMTP Relay.

You can configure Sendmail or Postfix to handle SMTP relay, but there is a service called SSMTP that is very simple and gets the job done with minimal effort.

SSMTP is unmaintained but works well. You can also look for alternatives such as MSMTP [Read It] or OpenSMTPD.

Note: SSMTP does not work in Raspbian 10 (Buster). Use MSMTP instead.

sudo apt-get update
sudo apt-get install ssmtp
sudo nano /etc/ssmtp/ssmtp.conf

Here is an example configuration for using it as a relay with Google:

mailhub=smtp.gmail.com:587
AuthUser=yourlogin@gmail.com
AuthPass=yourpassword
AuthMethod=LOGIN
UseTLS=Yes
UseSTARTTLS=Yes

Replace “yourlogin” with your Google account username and “yourpassword” with your password.

Using your real password is not ideal for two reasons. First, it will be stored as plain text, meaning other users on your server can read it. Second, you would need to enable “less secure apps” in your Google account settings [Link].

A better approach is to create an App Password (a password exclusive to this application) in your Google account settings, then copy and paste the generated password into the SSMTP configuration.

Steps (the links are shortcuts; if they do not work, just follow the steps manually):

  • Go to your Google account settings [Link].
  • Select Security [Link].
  • Under Signing in to Google, enable 2-Step Verification [Link].
  • Select App Passwords [Link].
  • Choose the app and device you want to generate the password for.
  • Click Generate.
  • Copy the password, which will look something like: msslu emqsa bifjbc.
  • Paste it into the SSMTP configuration file.

This App Password procedure also applies if you want to use Sendmail or Postfix as a Google relay.

All emails sent through the Google server will use your Google account address as the sender. Test it with:

echo -e 'Subject: test\n\nTesting ssmtp' | sendmail -v [email protected]