Рубрики
mail \ почта

Postfix relay \ yandex \ gmail \ отправка писем

Ссылки:

https://help.ubuntu.ru/wiki/postfix_relay_yandex
Configure Postfix to Use Gmail SMTP on Ubuntu
https://www.shellhacks.com/ru/postfix-gmail-relay-linux-mint-ubuntu-debian/

Решение для yandex:


0. Установка необходимых пакетов
sudo apt-get install postfix mutt

1. Заменяем содержимое /etc/postfix/main.cf
relayhost =
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/private/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_type = cyrus
smtp_sasl_mechanism_filter = login
smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/private/sender_relay
sender_canonical_maps = hash:/etc/postfix/private/canonical

2. Создаем папку /etc/postfix/private
sudo mkdir /etc/postfix/private


3. Создаем файлы для Postfix lookup tables
nano /etc/postfix/private/canonical
@yandex.ru	user@yandex.ru

nano /etc/postfix/private/sender_relay
@yandex.ru	smtp.yandex.ru

nano /etc/postfix/private/sasl_passwd
[smtp.yandex.ru]	user@yandex.ru:********

4. Создаем Postfix lookup tables
sudo postmap /etc/postfix/private/*

5. Пере запускаем сервис
sudo service postfix restart

6. Проверяем работу
Можно проверять работу с помощью, например, mutt 
Отправим тестовое сообщение на наш e-mail

echo "test" | mutt -s "test" nash@e-mail.ru
Чтобы добавить вложение используйте ключ -a

echo "test" | mutt -s "test" nash@e-mail.ru -a file

Решение для gmail

0. Установка Необходимых Пакетов
Выполните следующую команду для установки необходимых пакетов:
$ sudo apt-get install mailutils
Во время установки может появиться всплывающее окно. 
Если это произошло, выберите в качестве сервера Internet Site, а в качестве FQDN укажите domain.tld

1. Настройка Postfix с Релеем на Gmail

Откройте настройки Postfix:
$ sudo vi /etc/postfix/main.cf

Добавьте следующие строки:
# Relaying Postfix SMTP via GMAIL
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes


2. Установка Логина/Пароля от Gmail
Откройте (создайте) файл sasl_passwd:

$ sudo vi /etc/postfix/sasl_passwd
Добавьте следующую строку (укажите Ваш логин и пароль от Gmail):

[smtp.gmail.com]:587    ЛОГИН@gmail.com:ПАРОЛЬ
Установите права и скажите Postfix использовать файл sasl_passwd:

$ sudo chmod 400 /etc/postfix/sasl_passwd
$ sudo postmap /etc/postfix/sasl_passwd

3. Установка Сертификата

Добавьте в Postfix сертификат, выполнив следующую команду:
$ cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem


4. Проверка Postfix с SMTP Релеем через Gmail
Перезапустите Postfix для применения всех изменений.

$ sudo service postfix restart
Попробуйте отправить тестовое письмо на какой-нибудь почтовый ящик.

$ echo "Hello World" | mail -s "Test Message" you@example.com
Проверьте логи:

$ tail /var/log/mail.log