−Содержание
Centos MTA POSTFIX
настройка Postfix MTA (Mail Transfer Agent) Centos 6/7.
Удаление Sendmail
killall sendmail chkconfig --level 0123456 sendmail off yum remove 'sendmail*'
Установим Postfix
yum install postfix
Редактируем файл /etc/postfix/main.cf:
myhostname = host.domain.ru mydomain = domain.ru myorigin = $myhostname mynetworks = 127.0.0.0/8 relayhost = [relay host or ip]:port
Ставим переадресацию локальных и системных сообщений в /etc/aliases на внешний ящик:
root: user@my_server.ru
Перекомпилируем базу алиасов:
cd /etc newaliases
Запускаем Postfix:
service postfix start
Авто-запуск:
chkconfig --level 345 postfix on
Postfix – Gmail
yum install cyrus-sasl cyrus-sasl-lib cyrus-sasl-devel cyrus-sasl-plain openssl openssl-perl openssl-devel xmlsec1-openssl
Copy root CA certificates. Postfix должен знать его местонахождение
cp /etc/pki/tls/certs/ca-bundle.crt /etc/postfix/cacert.pem
Создадим файл sasl_passwd
nano /etc/postfix/sasl_passwd
smtp.gmail.com user@gmail.com:password
chmod 400 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
Редактируем /etc/postfix/main.cf
# Relay all e-mail via GMail. relayhost = [smtp.gmail.com]:587
inet_protocols = ipv4
# SASL authentication smtp_sasl_auth_enable=yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = smtp_sasl_tls_security_options = noanonymous smtp_sasl_mechanism_filter = login # TLS smtp_tls_eccert_file = smtp_tls_eckey_file = smtp_use_tls = yes smtp_enforce_tls = no smtp_tls_CAfile = /etc/postfix/cacert.pem smtpd_tls_received_header = yes tls_random_source = dev:/dev/urandom
service postfix restart
Включите доступ для непроверенных приложений в настройках аккаунта Google:
https://www.google.com/settings/security/lesssecureapps
Даже когда, ненадежные приложения разрешены, почта может не отправляться в течении некоторого времени.
postfix/smtp[]: : SASL authentication failed; server smtp.gmail.com[74.125.71.109] said: 534-5.7.9 Please log in with your web browser and then try again. Learn more at?534 5.7.9 https://support.google.com/mail/answer/78754 ei8sm19468869wjd.32 - gsmtp
Postfix – Yandex Mail
Добавляем в файл /etc/postfix/main.cf:
mydomain=domain.ru
myorigin = $mydomain
inet_protocols = ipv4
smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/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/sender_relay sender_canonical_maps = hash:/etc/postfix/canonical smtp_generic_maps = hash:/etc/postfix/generic smtp_use_tls = yes
В /etc/postfix/sasl_passwd указываем логин и пароль:
[smtp.yandex.ru] user@domain.ru:password
В /etc/postfix/sender_relay указываем привязку доменов и конкретных отправителей к внешним службам:
@domain.ru [smtp.yandex.ru] user@domain.ru [smtp.yandex.ru]
В /etc/postfix/canonical добавляем для домена указание через какой аккаунт отправлять почту:
@domain.ru user@domain.ru root fax
В /etc/postfix/generic добавляем отправку почты админу:
root@localhost olegus@asterisk-pbx.ru
И выполняем команду postmap для /etc/postfix/generic, /etc/postfix/canonical, /etc/postfix/sender_relay, /etc/postfix/sasl_passwd:
postmap /etc/postfix/generic && postmap /etc/postfix/canonical && postmap /etc/postfix/sender_relay && postmap /etc/postfix/sasl_passwd
Mail Log
tail -f /var/log/maillog
Дополнительно
Команды – Sendmail, mail, mutt
sendmail user@example.com < /tmp/email.txt
mail -s "Test Email" user@example.com < /dev/null
mail -a /opt/backup.sql -s "Backup File" user@example.com < /dev/null
mail -s "Test Email" user@example.com,user2@example.com < /dev/null
mutt -s "backup" -a /var/spool/asterisk/backup/Default_backup/sql.tgz -- mail@mail.tld < /home/mail.txt