Postfix + Dovecot でメールサーバを構築してみた。
参考にさせて頂いたページ
- http://centossrv.com/postfix.shtml
- http://park1.wakwak.com/~ima/centos_postfix_relay0001.html
- http://www.postfix-jp.info/trans-2.3/jhtml/postconf.5.html
環境
- サクラVPS
- CentOS 6.4
- postfix-2.6.6
- dovecot-2.0.9
- cyrus-sasl-2.1.23
Postfixの設定(Gmailと連携)
/etc/postfix/main.cfを編集。
myhostname = mail.test.com
mydomain = test.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
unknown_local_recipient_reject_code = 550
mynetworks_style = 192.168.32.0/23, 127.0.0.0/8
mynetworks = 192.168.32.0/23, 127.0.0.0/8
relay_domains = $mydestination
relayhost = [smtp.gmail.com]:587
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP unknown
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
smtp_sasl_security_options =
smtp_tls_CApath = /etc/pki/tls/certs/ca-bundle.crt
smtpd_tls_auth_only = no
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
message_size_limit = 10485760
GmailのSASL認証準備
>vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 test@gmail.com:password
>postmap hash:/etc/postfix/sasl_passwd
>postfix reload
サービス再起動
>service postfix restart
構築時に詰まったところ。
Gmailの認証が通らない
/var/log/maillogを確認。
(SASL authentication failed; server smtp.gamil.com[74.125.23.109] said: 534-5.7.9 Application-specific password required. Learn more at?534 5.7.9 http://support.google.com/accounts/bin/answer.py?answer=185833 1sm2519459pdw.87 - gstmp)
/etc/postfix/sasl_passwdに連携するGmailのアカウントのmail-address:passwordを記入する必要性があるが、全く認証が通らずに外部にメールが送れなかった・・・。
ので、
Gmailのセキュリティ設定でアプリケーション用パスワードを取得し、記入することで解決できた。
ちょっとした詰まるところ
- サービスが立ち上がっているか
- ポートが開いているか
- SMTP:25
- POP3:110
- mynetworksの設定がホストアドレスになっていないか
- myhostnameが名前解決できるようにDNS設定できているか
Dovecotの設定
/etc/dovecot/10-auth.confを編集。
disable_p;aintext_auth = no
/etc/dovecot/10-mail.confを編集。
mail_location = maildir:~/Maildir
サービス再起動
service dovecot restart