由於安全因素,阿裏雲會封掉25port, 這導致我們自建的監控系統無法發送郵件,因為是輕量型應用,申請解封失敗,遂按照推薦的方式采用了465 port 和relay的模式進行告警郵件的發送
組件構成:
壹個main,cf
壹個master.cf
壹個sasl_password? 和生成的sasl_password.db
壹個generic 和生成的generic.db文件
步驟:
由於我們使用的是ubuntu18.04,所以此處以此為例:
#安裝postfix?
apt upgrade
apt install postfix? ,選擇 Internet Site (? 如果安裝了sendmail 請將其停止或者卸載)
#添加465端口發信
vim /etc/postfix/master,cf
添加 smtps inet n - - - - smtpd
解除註釋:?-o smtpd_tls_wrappermode=yes
!wq 保存退出
vim /etc/services
添加 smtps 465/tcp mail2
smtps 465/udp mail2
#創建相關授權文件及虛擬映射文件
vim /etc/postfix/sasl_passwd
[smtp.163.com]:465 username@163.com:授權碼
!wq? 保存退出
postmap /etc/postfix/sasl_passwd 生成sasl_passwd.db 文件
vim /etc/postfix/generic
root@monitor username@163.com (#要和上面文件內的壹樣)
!wq 保存退出
postmap /etc/postfix/generic 生成generic.db 文件
#編輯主配置文件
vim /etc/postfix/main.cf
新增如下:
smtp_sasl_auth_enable = yes
#smtp_sasl_type = cyrus
smtp_sasl_security_options=noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_security_level = encrypt
smtp_tls_wrappermode = yes
smtp_generic_maps = hash:/etc/postfix/generic
修改如下:
inet_protocols = ipv4
#重啟服務
systemctl restart postfix
測試發送,如有問題請檢查log
主要報錯:
1
status=deferred (delivery temporarily suspended: lost connection with smtp.163.com[220.181.12.12] while receiving the initial server greeting)
要配置relay 模式
2:
status=deferred (SASL authentication failed; cannot authenticate to server smtp.163.com[220.181.12.17]: no mechanism available)
修改/etc/postfix/main.cf
smtp_sasl_security_options=noanonymous
3:
status=bounced (host smtp.163.com[220.181.12.16] said: 553 Mail from must equal authorized user (in reply to MAIL FROM command))
修改 /etc/postfix/generic 把主機名和郵箱名字修復正確。
4
postfix/smtp[3218]: SMTPS wrappermode (TCP port 465) requires setting "smtp_tls_wrappermode = yes", and "smtp_tls_security_level = encrypt" (or stronger)
按照報錯提示在主文件添加相關配置項
參考資料: /post/postfix-use-external-smtp/