Set up sending mail via sSMTP on Linux
This is an instruction for configuring mailings via the Selectel mail service using the sSMTP utility on a Linux server.
-
Make sure that you have enabled the mail service for the domain and the domain has received the status `Verified'. The connected domains and their statuses can be viewed in the [control panel](https://my.selectel.ru/ses /) in the section Mail service → resource page → tab Information → block Linked domains.
-
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 via KVM console.
Connect to the server via SSH or via 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 auxiliary utility
mailx
to send mail:Debian / Ubuntu
CentOS
sudo apt install mailutils
sudo apt install mailx
-
Install the
nano
:Debian / Ubuntu
CentOS
sudo apt install nano
sudo yum install nano
-
Open the configuration file
ssmtp.conf
: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
# If <port>=1126, then 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 need to establish a TLS (SSL) connection.
-
<login>
— login, you can view it in the [control panel](https://my.selectel.ru/ses /) in the Mail service section → the page of the resource to which the domain has been added → the Information tab; -
<password>
— the password can be viewed in the [control panel](https://my.selectel.ru/ses /) in the Mail service section → the page of the resource to which the domain has been added → the Information tab; -
<example.com >
is the domain from which you want 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
# If <port>=1126, then 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 need to establish a TLS (SSL) connection.
-
<login>
— login, can be viewed in the [control panel](https://my.selectel.ru/ses /) in the Mail service section → the page of the resource to which the domain has been added → the Information tab; -
<password>
— the password can be viewed in the [control panel](https://my.selectel.ru/ses /) in the Mail service section → the page of the resource to which the domain has been added → the Information tab; -
<example.com >
is the domain from which you want to send mailings.
-
Close the file (Ctrl+X) and save the changes (Y).
-
Open the
revaliases
configuration file:sudo nano /etc/ssmtp/revaliases
-
Add a line with the address that should be displayed as the sender's address in mailings via the mail service:
root:<sender_email>:smtp.mail.selcloud.ru:<port>
Specify:
<sender_email>
— the sender's address on the domain that you have connected to the mail service, for example,sender@example.com
;<port>
is the port that was 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
ssmtp
instead of `sendmail':sudo ln -s /usr/sbin/ssmtp /usr/sbin/sendmail
-
Send a test newsletter:
$ echo test | mail -s "testing ssmtp" <recipient_email>
Specify the
<recipient_email>
address to which you want to send the test newsletter.