Skip to main content
Configure sending mail via sSMTP on Linux
Last update:

Configure sending mail via sSMTP on Linux

For your information

These are instructions for setting up mailings through the Selectel mail service using the sSMTP utility on a Linux server.

  1. Make sure that you have connected the mail service for the domain and the domain has been given a status of Verified. Connected domains and their statuses can be viewed in the control panel under Postal service → resource page → tab Information → block Bound domains.

  2. Connect to the server in the Selectel infrastructure from which you plan to send mailings:

    Connect to the server SSH or via KVM console.

  3. Install sSMTP:

    sudo apt update
    sudo apt install ssmtp
  4. Install the auxiliary utility mailx to send the mail:

    sudo apt install mailutils
  5. Set nano:

    sudo apt install nano
  6. Open the configuration file ssmtp.conf:

    nano /etc/ssmtp/ssmtp.conf
  7. Change the contents of the file:

    mailhub=smtp.mail.selcloud.ru:<port>
    AuthUser=<login>
    AuthPass=<password>
    AuthMethod=LOGIN
    rewriteDomain=<example.com>
    hostname=smtp.mail.selcloud.ru
    FromLineOverride=No
    UseSTARTTLS=Yes
    UseTLS=Yes
    # Если <port>=1126, то UseTLS=No
    TLS_CA_File=/etc/ssl/certs/ca-certificates.crt

    Specify:

    • <port> — port:

      • 1126 — if you need to establish a no SSL / STARTTLS connection;
      • 1127 — if you want to establish a TLS (SSL) connection.
    • <login> — login, you can look at control panel under Postal service → page of the resource to which the domain is added → tab Information;

    • <password> — password, you can look in control panel under Postal service → page of the resource to which the domain is added → tab Information;

    • <example.com> — the domain from which to send mailings.

  8. Close the file (Ctrl+X) and save your changes (Y).

  9. Open the configuration file revaliases:

    sudo nano /etc/ssmtp/revaliases
  10. Add a string with the address that should appear as the sender's address in mailings through the mailing service:

    root:<sender_email>:smtp.mail.selcloud.ru:<port>

    Specify:

    • <sender_email> — the sender address on the domain you have connected to the mail service, e.g. sender@example.com;
    • <port> — port that you specified in step 7.
  11. Close the file (Ctrl+X) and save your changes (Y).

  12. Replace the default mail sender with the configured sSMTP:

    sudo mv /usr/sbin/sendmail /usr/sbin/sendmail.orig
  13. Create a symlink to ssmtp instead of sendmail:

    sudo ln -s /usr/sbin/ssmtp /usr/sbin/sendmail
  14. Send a test mailing:

    $ echo test | mail -s "testing ssmtp" <recipient_email>

    Specify <recipient_email> — the address to which you want to send the test mailing.