Python 3-SMTPNotSupportedError

问题描述 投票:0回答:1

我一直在使用Python 3从我的Gmail帐户发送电子邮件。

当我在Windows 7 PC上使用代码时,收到以下错误:

File "C:\Program Files\Python38\lib\smtplib.py", line 755, in starttls
    raise SMTPNotSupportedError(
smtplib.SMTPNotSupportedError: STARTTLS extension not supported by server.

我正在使用3.8.1 64位版本,也尝试了3.7.4 32位版本,并遇到相同的错误。

我已经在Debian上运行了相同的代码,并且完全没有错误。电子邮件发送无误。

这是脚本:

import smtplib

from email.message import EmailMessage

msg = EmailMessage()
msg.set_content('Email sending example using Python. It\'s Simple Text Message')

fromEmail = '[email protected]'
toEmail = '[email protected]'

msg['Subject'] = 'Simple Text Message'
msg['From'] = fromEmail
msg['To'] = toEmail

s = smtplib.SMTP('smtp.gmail.com', 587)

s.starttls()

s.login(fromEmail, 'Password')
s.send_message(msg)
s.quit()

我已经搜索了Google和S.O.但我一直找不到解决方法。

我总是能够在早期版本的Python(3.5)上运行这种类型的脚本

非常感谢。

windows-7-x64 smtplib python-3.8
1个回答
0
投票

重新启动计算机后,代码按预期开始工作。

© www.soinside.com 2019 - 2024. All rights reserved.