Python SMTPException: No suitable authentication method found

最近在发送邮件日报时, 使用smtplib库抛了一个异常raise SMTPException("No suitable authentication method found.")

原因是配置了https的邮件服务器, 在初始化SMTP和login之间调用starttls()方法即可解决问题

1
2
3
4
5
6
7
import smtplib
server = smtplib.SMTP(self.server, self.port)
server.set_debuglevel(1)
server.starttls()
server.login(self.send_user, self.password)
server.sendmail(self.send_user, [to], msg.as_string())
server.quit()