sudo apt install -y postfix mailutils libsasl2-modules sasl2-bin
sudo dpkg-reconfigure postfix
  • General type of mail configuration → Internet with smarthost
  • System mail name → mail.example.com
  • SMTP relay host → [smtp.yandex.com]:465
sudo postconf -e 'relayhost = [smtp.yandex.com]:465'
sudo postconf -e 'smtp_sasl_auth_enable = yes'
sudo postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
sudo postconf -e 'smtp_sasl_security_options = noanonymous'
sudo postconf -e 'smtp_sasl_type = cyrus'
sudo postconf -e 'smtp_tls_wrappermode = yes'
sudo postconf -e 'smtp_tls_security_level = encrypt'
sudo postconf -e 'smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt'
sudo postconf -e 'smtp_generic_maps = hash:/etc/postfix/generic'
sudo nano /etc/postfix/sasl_passwd
[smtp.yandex.com]:465 ТВОЙ_ЯНДЕКС_АДРЕС:ТВОЙ_APP_PASSWORD
sudo nano /etc/postfix/generic
www-data@localhost ТВОЙ_ЯНДЕКС_АДРЕС
root@localhost ТВОЙ_ЯНДЕКС_АДРЕС
www-data@mail.example.com ТВОЙ_ЯНДЕКС_АДРЕС
root@mail.example.com ТВОЙ_ЯНДЕКС_АДРЕС
sudo postmap /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/generic
sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db /etc/postfix/generic /etc/postfix/generic.db
sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db /etc/postfix/generic /etc/postfix/generic.db
sudo systemctl restart postfix

Проверка:

sudo postconf relayhost smtp_sasl_auth_enable smtp_tls_wrappermode smtp_generic_maps

Должно показать:

  • relayhost = [smtp.yandex.com]:465
  • smtp_sasl_auth_enable = yes
  • smtp_tls_wrappermode = yes
  • smtp_generic_maps = hash:/etc/postfix/generic