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 notification, password reset, and so on. And there is no need to have a full email server with domain and user accounts. The SMTP will serve the applications by relaying to an external SMTP server.
    • That is the case covered by the example in this post.
  • SMTP Server: The applications need to send emails for notification, password reset, and so on. The e-mail server of the domain is external, and this server will also send emails for this domain. The SMTP will serve the applications as an SMTP server.
  • E-Mail Server: The server is the e-mail server of a domain and needs to have accounts, SMTP, and serve the local and external applications.

Using SSMTP with Google SMTP Relay:

The easiest and maybe the most popular is the SMTP Relay.

You configure the Sendmail or the Postfix to do the SMTP relay, but there is one service college SSMTP that is very simple and makes the job done with no effort.

SSMTP is unmaintained but works pretty fine. You can also search for alternatives, such as MSMTP [Read It] or OpenSMTPD.

SSMTP does not work in Raspbian 10 (Buster), try MSMTP.

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

It is an example of usage as a relay with Google:

Replace “yourlogin” by your Google user account (twice) then insert “yourpassword“.

Using your real password is not the best way for two reasons. First, it will be stored as plain text and other users of your server can read it. Second, you have to go into your configuration account and allow “less secure apps” [Link].

You can create an API Password (one password exclusive for this application) in your Google account configuration, copy, and paste the random password in the SSMTP.

Steps (the links are shortcuts, if not working just follow the steps):

  • Enter your Google account settings [Link].
  • Select¬†Security [Link].
  • In Signing in to Google enable 2-Step Verification [Link].
  • Select App Passwords [Link].
  • Select the app and device you want to generate the app password for.
  • Click Generate.
  • Copy the password that may log line this: msslu emqsa bifjbc.
  • Then paste in the SSMTP configuration file.

This App Password procedure might be the same if you want to user Sendmail or Postfix as Google relay.

All the e-mails sent using the Google server will have the sender e-mail the same as your account e-mail. Test it!

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