Configure email sending via sSMTP on Linux
This guide explains how to configure email campaigns using the Selectel mail service via the sSMTP utility on a Linux server.
-
Ensure that you have connected a mail service for the domain and that the domain has the status
Verified. You can view connected domains and their statuses in the control panel: in the top menu, click Products → Mail Service → resource page → Information tab → Linked domains block. -
Connect to the server in the Selectel infrastructure from which you plan to send emails:
Dedicated server
Cloud server
Connect to the server via SSH or via KVM console.
-
Install sSMTP:
Debian / Ubuntu
CentOS
sudo apt updatesudo apt install ssmtp -
Install the
mailxutility to send emails:Debian / Ubuntu
CentOS
sudo apt install mailutils -
Install
nano:Debian / Ubuntu
CentOS
sudo apt install nano -
Open the
ssmtp.confconfiguration file:nano /etc/ssmtp/ssmtp.conf -
Edit the file content:
Debian / Ubuntu
CentOS
mailhub=smtp.mail.selcloud.ru:<port>AuthUser=<login>AuthPass=<password>AuthMethod=LOGINrewriteDomain=<example.com>hostname=smtp.mail.selcloud.ruFromLineOverride=NoUseSTARTTLS=YesUseTLS=Yes# If <port>=1126, then UseTLS=NoTLS_CA_File=/etc/ssl/certs/ca-certificates.crtSpecify:
-
<port>— port:1126— if you need to establish a non-SSL / STARTTLS connection; ;1127— if you need to establish a TLS (SSL) connection.
-
<login>— login, which can be found in the control panel: in the top menu, click Products → Mail Service → resource page to which the domain is added → Information tab; -
<password>— password, which can be found in the control panel: in the top menu, click Products → Mail Service → resource page to which the domain is added → Information tab; -
<example.com>— the domain you want to send emails from.
-
Close the file ( **Ctrl+X **) and save the changes ( **Y **). .
-
Open the
revaliasesconfiguration file:sudo nano /etc/ssmtp/revaliases -
Add a line with the address that should be displayed as the sender address in email campaigns via the mail service:
root:<sender_email>:smtp.mail.selcloud.ru:<port>Specify:
<sender_email>— the sender address on the domain you connected to the mail service, for examplesender@example.com;<port>— the port you specified in step 7.
-
Close the file ( **Ctrl+X **) and save the changes ( **Y **). .
-
Replace the default mail sender with the configured sSMTP:
sudo mv /usr/sbin/sendmail /usr/sbin/sendmail.orig -
Create a symlink to
ssmtpinstead ofsendmail:sudo ln -s /usr/sbin/ssmtp /usr/sbin/sendmail -
Send a test email:
$ echo test | mail -s "testing ssmtp" <recipient_email>Specify
<recipient_email>— the address you want to send the test email campaign to.