服务器配置qq邮箱发送信息

登录网页版的QQ邮箱

(旧版邮箱)设置-账号-开启SMTP

这时候会获取到一个 授权码 保存备用

安装邮箱客户端Postfix

sudo apt-get install postfix

配置Postfix:编辑Postfix的主要配置文件 /etc/postfix/main.cf,并在最后添加以下参数:

屏蔽掉

#relayhost = 
relayhost = [smtp.qq.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
maillog_file = /var/log/mail.log
debug_peer_level = 2

最终的

image-20250507195011903

/etc/postfix目录下创建sasl_passwd 文件并编辑

[smtp.qq.com]:587  [email protected]:刚才获取到的授权码

确保文件可被读取

sudo chmod 600 /etc/postfix/sasl_passwd

生成 sasl_passwd 文件的哈希映射:

sudo postmap /etc/postfix/sasl_passwd

重新加载 Postfix 配置:

sudo systemctl reload postfix

安装mailutils

apt-get install mailutils -y

测试发送(注意防火墙端口587开启)

echo "This is a test email"   | mail -s "Test Email" -r "[email protected]" [email protected]

image-20250507195550139

参考:https://blog.csdn.net/weixin_47540149/article/details/133958508

如果觉得我的文章对你有用,请随意赞赏