Configure sending mail via sSMTP on Linux
These are instructions for setting up mailings through the Selectel mail service using the sSMTP utility on a Linux server.
-
Make sure that you have connected the mail service for the domain and the domain has received the
Verified
status. You can view connected domains and their statuses in the control panel: in the top menu, click Products → Mail Service → Resource page → Information tab → Bound Domains block. -
Connect to the server in the Selectel infrastructure from which you plan to send mailings:
Dedicated server
Cloud server
Connect to the server via SSH or KVM console.
Connect to the server using SSH protocol or through the console in the control panel.
-
Install sSMTP:
Debian / Ubuntu
CentOS
sudo apt update
sudo apt install ssmtpsudo yum update
sudo yum install ssmtp -
Install the
mailx
helper utility to send mail:Debian / Ubuntu
CentOS
sudo apt install mailutils
sudo apt install mailx
-
Install
nano
:Debian / Ubuntu
CentOS
sudo apt install nano
sudo yum install nano
-
Open the
ssmtp.conf
configuration file:nano /etc/ssmtp/ssmtp.conf
-
Change the contents of the file:
Debian / Ubuntu
CentOS
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.crtSpecify:
-
<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, can be viewed in control panel: in the top menu click Products → Mail service → the page of the resource to which the domain has been added → tab Info; -
<password>
— password, can be viewed in control panel: in the top menu, click Products → Mail service → the page of the resource to which the domain has been added → tab Info; -
<example.com>
— domain from which to send mailings.
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/pki/tls/certs/ca-bundle.crtSpecify:
-
<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, can be viewed in control panel: in the top menu click Products → Mail service → the page of the resource to which the domain has been added → tab Info; -
<password>
— password, can be viewed in control panel: in the top menu, click Products → Mail service → the page of the resource to which the domain has been added → tab Info; -
<example.com>
— domain from which to send mailings.
-
Close the file **(Ctrl+X **) and save your changes ( **Y **).
-
Open the
revaliases
configuration file:sudo nano /etc/ssmtp/revaliases
-
Add a string with the address to be displayed as the sender's address in mailings through the mailing service:
root:<sender_email>:smtp.mail.selcloud.ru:<port>
Specify:
<sender_email>
— sender address on the domain you have connected to your mail service, e.g.sender@example.com
;<port>
— the port you specified in step 7.
-
Close the file **(Ctrl+X **) and save your changes ( **Y **).
-
Replace the default mail sender with the configured sSMTP:
sudo mv /usr/sbin/sendmail /usr/sbin/sendmail.orig
-
Create a symlink to
ssmtp
instead ofsendmail
:sudo ln -s /usr/sbin/ssmtp /usr/sbin/sendmail
-
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.