SMTP AUTH extension trouble with Python

╄→尐↘猪︶ㄣ 提交于 2019-12-01 09:34:56

The error you get means the SMTP server you're talking to doesn't claim to support authentication. If you look at the debug output you'll see that none of the responses to your EHLOs contain the necessary declaration for AUTH. If it did (properly) support authentication, one of the responses would be something like:

250 AUTH GSSAPI DIGEST-MD5 PLAIN

(at least in reponse to the EHLO after the STARTTLS.) Because that response isn't included, smtplib assumes the server won't be able to handle the AUTH command, and will refuse to send it. If you're certain your SMTP server does support the AUTH command even though it doesn't advertise it, you can sneakily convince smtplib that it supports AUTH by explicitly adding it to the set of features. You'll need to know which kind of authentication schemes are supported, and then you can do:

smtp.starttls()
smtp.ehlo()
# Pretend the SMTP server supports some forms of authentication.
smtp.esmtp_features['auth'] = 'LOGIN DIGEST-MD5 PLAIN'

... but of course making the SMTP server behave according to spec would be a better idea :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!