开始
apt install libsasl2-modules -y
新建 /etc/postfix/sasl_passwd 文件,添加一行,格式为 SMTP服务器[空格]SMTP认证用户名[冒号]密码 如:
smtp.gmail.com username@gmail.com:12345678
postmap hash:/etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
generic映射本机用户到smtp账号
新建 /etc/postfix/generic 文件,添加一行,格式为 root@pve.lan support@haiyun.me 如:
postmap hash:/etc/postfix/generic
chmod 600 /etc/postfix/generic
修改postfix配置 /etc/postfix/main.cf 尾部增加
relayhost = smtp.gmail.com:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem
smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
smtp_tls_session_cache_timeout = 3600s
保存并重载postfix
postfix reload
测试一下
echo "test message" | mail -s "test subject" youremail@gmail.com