安装认证模块:
apt install libsasl2-modules
#如需pcre匹配安装
#apt install postfix-pcre
修改/etc/postfix/main.cf添加:
myhostname=pve.lan
#配置文件内有relayhost要先注释,465端口是SMTPS,587端口是STARTTLS
relayhost = smtp.qq.com:465
#此参数被smtp_tls_security_level取代
#smtp_use_tls = yes
#使用SMTPS非STARTTLS加密方式
smtp_tls_wrappermode = yes
#加密级别
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
#本地用户替换为smtp认证用户,smtp_generic_maps和sender_canonical_maps都可以
smtp_generic_maps = hash:/etc/postfix/generic
#sender_canonical_maps = hash:/etc/postfix/sender_canonical
#使用pcre匹配本机用户
#sender_canonical_maps = pcre:/etc/postfix/sender_pcre_canonical
#header检查并替换发送者名称
smtp_header_checks = pcre:/etc/postfix/smtp_header_checks
sender_canonical或generic映射本机用户到smtp账号:
cat /etc/postfix/generic
#本机所有用户,注意pve.lan为主配置文件myhostname
@pve.lan support@haiyun.me
#下面2个等效
root support@haiyun.me
root@pve.lan support@haiyun.me
正则映射:
cat /etc/postfix/sender_pcre_canonical
#匹配所有hostname和所有用户
/.*/ support@haiyun.me
smtp账号密码:
cat /etc/postfix/sasl_passwd
smtp.qq.com support@haiyun.me:password
生成hash数据库,pcre不用生成:
postmap /etc/postfix/sasl_passwd
postmap /etc/postfix/generic
postmap /etc/postfix/sender_canonical
替换发件人姓名:
cat /etc/postfix/smtp_header_checks
/^From:.*/ REPLACE From: 重要通知 <support@haiyun.me>
发送邮件测试:
apt install bsd-mailx
echo "www.haiyun.me" |mail -s test support@haiyun.me
echo "test" | /usr/bin/pvemailforward
将其它用户邮件转发到root用户:
cat /etc/aliases
postmaster: root
nobody: root
#也可使用~/.forward
#root: support@haiyun.me
postalias /etc/aliases
将root用户邮件转发到外部邮箱:
cat ~/.forward
support@haiyun.me
参考:
https://serverfault.com/questions/717719/how-can-i-strip-or-rewrite-the-senders-name-of-a-from-address-when-using-postfi
https://forum.proxmox.com/threads/get-postfix-to-send-notifications-email-externally.59940/