如何修复HomeAssistant中notify.send_email的SMTP连接超时问题?
修复HomeAssistant中QQ邮箱SMTP通知连接超时问题
问题场景
- 本地Python代码通过
smtplib.SMTP_SSL连接QQ邮箱465端口,能正常发送邮件 - HomeAssistant配置SMTP通知后,出现连接超时错误,日志提示
smtplib.SMTPServerDisconnected: Connection unexpectedly closed: timed out
原因分析
QQ邮箱的465端口为SSL直连端口,要求直接建立加密连接;而配置中使用的encryption: starttls是先建立明文连接再升级为SSL,两者模式不匹配,导致连接超时。
解决方案
方案一:使用SSL加密(对应465端口)
修改configuration.yaml中的加密方式为ssl:
notify: - name: "send_email" platform: smtp server: "smtp.qq.com" port: 465 timeout: 15 sender: "x1@qq.com" encryption: ssl username: "x1@qq.com" password: "xxxx" recipient: - "x2@qq.com" sender_name: "send by homeassistant"
方案二:使用STARTTLS加密(对应587端口)
如果偏好STARTTLS模式,将端口改为587并保留encryption: starttls:
notify: - name: "send_email" platform: smtp server: "smtp.qq.com" port: 587 timeout: 15 sender: "x1@qq.com" encryption: starttls username: "x1@qq.com" password: "xxxx" recipient: - "x2@qq.com" sender_name: "send by homeassistant"
额外注意事项
- 确认配置中的
password是QQ邮箱的SMTP授权码,而非账号登录密码(需在QQ邮箱设置中开启POP3/SMTP服务并生成) - 检查HomeAssistant所在网络是否能访问对应端口(465/587),无防火墙或路由器拦截
内容的提问来源于stack exchange,提问作者showkey
相关产品推荐
相关产品推荐

