提问人:Alex Ironside 提问时间:10/31/2023 最后编辑:user3783243Alex Ironside 更新时间:10/31/2023 访问量:38
通过Gmail发送电子邮件时程序卡住
program gets stuck when sending email via gmail
问:
我有以下python函数:
import smtplib, ssl
port = 465 # For SSL
password = "valid password"
context = ssl.create_default_context()
def sendEmail(to_email, subject, content):
from_email = "[email protected]"
message = (f"Tresc zadania: {content}",)
try:
print("connecting")
with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
print("connected")
server.login("[email protected]", password)
print("logged")
server.sendmail(
to_addrs=to_email,
from_addr=from_email,
msg=message,
)
print("sent")
except Exception as e:
print(e.message)
以下是日志:
connecting
connected
logged
因此,它会连接,登录到谷歌邮件,但在尝试发送电子邮件时会卡住。
我错过了什么?
我允许不太安全的应用程序,密码是从谷歌安全 2FA 选项卡(应用程序密码)生成的。
答: 暂无答案
评论
zaliczenie.pl