Postfix

来自百合仙子's Wiki
跳转到导航 跳转到搜索

安全与反垃圾

Postfix 默认允许同子网内的机器发送 relay 邮件(mynetworks_style = subnet)。

要禁止来自不正确的域名、不存在的域名的邮件,在 /etc/postfix/main.cf 中写上:[1]

smtpd_sender_restrictions = permit_mynetworks, reject_non_fqdn_sender, reject_unknown_sender_domain, permit

TLS

/etc/postfix/main.cf 中写上:

smtpd_tls_cert_file = /etc/letsencrypt/live/host/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/host/privkey.pem
smtp_tls_security_level = may
smtpd_tls_security_level = may

别名

.forward 文件

投递到指定命令,如 procmail,只需要在 ~/.forward 文件里写上:

| procmail

通过腾讯邮箱发信

main.cf 中配置:[2]

# 指定接受的收件人域名。我们使用 PCRE 来指定全部
relay_domains = pcre:/etc/postfix/relay_domains

relayhost = [smtp.exmail.qq.com]:587

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_sender_dependent_authentication = yes

# rewrite MAIL FROM on envelopes
canonical_maps = regexp:/etc/postfix/canonical
canonical_classes = envelope_sender

/etc/postfix/relay_domains 里配置允许的收件人域名为任意域名:

/.*/ .

/etc/postfix/sasl_passwd 里配置登录信息:

[smtp.exmail.qq.com]:587 user@example.com:password

/etc/postfix/canonical 里配置 MAIL FROM 地址重写:[3]

// user@example.com

生成 hash 数据库并更改权限:

postmap /etc/postfix/sasl_passwd
postmap /etc/postfix/canonical
chmod 600 /etc/postfix/sasl_passwd*

重新加载配置:

systemctl reload postfix

转发

因为各种原因(比如 SPF、TLS 等),服务器 A 想通过服务器 B 发送邮件,如下配置 main.cf

服务器 B 允许转发来自 A 的邮件

mynetworks = 127.0.0.0/8, [::1]/128, A 的 IP 地址

服务器 A 通过 B 转发

mydomain = 邮送域
relayhost = [B 的域名或 IP]

调试

debug_peer_list = smtp.exmail.qq.com
smtp_tls_loglevel = 4

参见

外部链接

参考资料