我正在尝试使用amazon价格跟踪器的smtp模块发送gmail电子邮件。几天前,它工作正常,但今天它出现了以下错误:
File "C:\Users\61409\AppData\Local\Programs\Python\Python39\lib\smtplib.py", line 755, in starttls
raise SMTPNotSupportedError(
smtplib.SMTPNotSupportedError: STARTTLS extension not supported by server.
这是最初工作但给出错误的代码:
import smtplib
def send_email():
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('xxxxxxxx@gmail.com', '*password*')
subject = f'The price of your product has fallen'
body = f'Check the amazon link - {URL}'
msg = f"Subject: {subject}\n\n{body}"
server.sendmail(
'xxxxxxx@gmail.com',
'xxxxxxx@gmail.com',
msg
)
print('The email has been sent')
server.quit()
我尝试过创建另一个gmail帐户并使用SSL(也导入SSL),但另一个gmail帐户遇到了相同的问题,当使用SSL时,它遇到了SMTP身份验证问题(也无法解决此问题)。我允许使用不太安全的应用程序,但同样的问题仍然存在。我也尝试过删除第一个server.ehlo()
,也尝试过使用server.set_debuglevel(1)
,但两者都不起作用。我也尝试过使用with stmplib.SMTP(*Host*, *Port*) as server:
,我尝试过只使用SMTP而不使用SSl和TLS,但这两个答案都不起作用。大多数答案都删除了smtplib.SMTPNotSupportedError: STARTTLS extension not supported by server.
,但也出现了其他问题,例如smtplib.SMTPServerDisconnected: Connection unexpectedly closed
,这在其他答案中发生了多次。我试图研究解决连接意外关闭的方法,但这些答案都不起作用
以下是我尝试过的答案:
SMTPException: STARTTLS extension not supported by server
smtplib.SMTPNotSupportedError: STARTTLS extension not supported by server
Python 2: SMTPServerDisconnected: Connection unexpectedly closed
Python3 SMTP 'Connection unexpectedly closed'
How to send an email with Python?
我如何解决这个问题?我是否遗漏了什么??我是否需要使用其他模块或库发送电子邮件???如果这是一个重复的问题,有一个可行的答案,我道歉。如果我提到的答案中有一个不起作用,除了我把代码搞错了之外,我也很抱歉
我遇到了同样的问题:
smtplib
工作正常,然后返回相同的错误,服务器(outlook)没有任何更改。 碰巧我重构了代码,发送电子邮件的功能在模块中更深入。 如果我用老办法,它会成功的! 当我关掉杀毒软件(在我的例子中是AVG)时,一切都很好! 因此,出于某种原因,代码重构使得发送过程被反病毒捕获到服务器的SMTP连接似乎不提供STARTTLS扩展,至少从客户端的角度来看是这样。此扩展在对客户端初始EHLO命令的响应中宣布:
PTM.Gmail网站肯定支持这个扩展,很可能在连接路径中的某个中间有一个人,将流量改写成这样的:这里,服务器的响应被更改为不再显示支持StuttLs,希望客户端继续不加密,从而可以分析中间的人的邮件。中间的这类人通常是企业防火墙,比如Cisco ASA,但也可以是ISP或local antivirus products。
检查本地安全产品(防病毒)或其设置是否有任何更改,或者您的环境是否有更改(公司防火墙、您使用的不同网络…)
相关问题 更多 >
编程相关推荐