Настройка Postfix

postfix logo

настройка 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
 

Hylafax Postfix Configuration

Hylafax Postfix Configuration

Hylafax Postfix Configuration

I found it very difficult to find documentation on how to setup Postfix to work with the Hylafax email to fax server. Here is how I got it to work:

(This post assumes you have installed hylafax rpms from their website at hylafax.org)

1. yum install postfix
2. service sendmail stop
3. chkconfig sendmail off
4. chkconfig postfix on
5. nano /etc/postfix/main.cf

Add/Edit:

myhostname = fax.DOMAINNAME.com
mydomain = DOMAINNAME.com
mydestination = $myhostname, localhost.$mydomain, localhost, fax.DOMAINNAME.com
local_recipient_maps =
transport_maps = hash:/etc/postfix/transport
fax_destination_recipient_limit = 1

6. nano /etc/postfix/master.cf
Add to the bottom:

fax unix – n n – 1 pipe
flags= user=fax argv=/usr/bin/faxmail -d -n -N -T ${user}

7. nano /etc/postfix/transport
Add to the bottom:

fax.DOMAINNAME.com fax:hylafax:4559

8. /usr/sbin/postmap /etc/postfix/transport
9. service postfix start

email to fax

email to fax

POSTFIX


1. Edit master.cf, add the following at the very bottom: # EMAIL TO FAX GATEWAY SETTINGS

fax       unix  -       n       n       -       1       pipe
  flags= user=fax argv=/usr/bin/faxmail -d -n ${user}

2. Edit transport file, add the following at the very bottom: # EMAIL TO FAX GATEWAY SETTINGS

fax.domain.com fax:localhost

3. Edit main.cf, add the following at the very bottom: # EMAIL TO FAX GATEWAY SETTINGS

transport_maps = hash:/etc/postfix/transport
fax_destination_recipient_limit = 1

4. Run the following: postmap transport 5. Restart the Postfix service: service postfix restart

Пример настройки работы Postfix через релэй с авторизацией:

Пример настройки работы Postfix через релэй с авторизацией:

Пример настройки работы Postfix через релэй с авторизацией:

/etc/postfix/main.cf

 relayhost = [testmail.ru]
 # auth_krasmail
 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
 smtpd_sasl_path = smtpd

/etc/postfix/sasl_passwd

 [testmail.ru]  user:password

и потом

 postmap sasl_passwd
 postfix reload

http://semi-legitimate.com/blog/item/how-to-rewrite-outgoing-address-in-postfix

Система

  • system/postfix.txt
  • Последние изменения: 2017/05/18