CentOS 6
1. 移除sendmail 安裝postfix
1 2 3 |
# /etc/init.d/sendmail stop # yum remove sendmail # yum install postfix cyrus-sasl mailx |
2. Gmail username and password
Simple Authentication and Security Layer (SASL)
1 2 3 |
# echo "smtp.gmail.com GMAIL_USERNAME:GMAIL_PASSWORD" > /etc/postfix/sasl_passwd # chmod 600 /etc/postfix/sasl_passwd # postmap hash:/etc/postfix/sasl_passwd |
3. Postfix 設定 vim /etc/postfix/main.cf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
myhostname = xxxx.hang321.net mydomain = hang321.net # use Gmail SMTP server. Remember to set on Google to allow access with less secure method relayhost = smtp.gmail.com:587 smtp_use_tls = yes smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous # set the required TLS options smtp_tls_CApath = /etc/ssl/certs smtp_tls_security_level = secure smtp_tls_mandatory_protocols = TLSv1 smtp_tls_mandatory_ciphers = high smtp_tls_secure_cert_match = nexthop |
CApath here, not CAfile
4. 重新啟動Postfix
1 |
# service postfix restart |
5. Google 安全性設定
https://myaccount.google.com/security
「我的帳戶」> 「低安全性應用程式」專區 > 「安全性較低的應用程式存取權限」旁邊的 [啟用]
6. 測試mail server 是否有正常寄信
寄信俾自己
1 2 |
Testing email, tail -f /var/log/maillog to see the result. # echo "body of your email" | mail -s "This is a Subject" recipient@example.com |
後記:
Goolge 可能係最近才有這個安全性設定,大多數reference 都沒有提及,搞到我白忙一場。
不同Linux distro, CA file name 有分別。