通过python向邮箱发送带附件的邮件,本地测试没问题,但在生产环境中跑就失败了,报错如下:
File "/usr/local/lib/python3.7/smtplib.py", line 861, in sendmail (code, resp) = self.mail(from_addr, esmtp_opts)
File "/usr/local/lib/python3.7/smtplib.py", line 535, in mail return self.getreply()
File "/usr/local/lib/python3.7/smtplib.py", line 394, in getreply raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
错误内容:smtplib断开连接:连接意外关闭。
smtplib.SMTP_SSL(smtp_host)
连接,其中 smtp_host = ‘smtp.exmail.qq.com’。smtp.login()
前加上 smtp.starttls()
。若端口为465,则不需要TLS连接,加上反而会报错。