gpt4 book ai didi

python - 无法使用 pyramid_mailer 和 gmail 发送电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 13:51:49 25 4
gpt4 key购买 nike

我正在尝试使用我的 gmail smtp 和 pyramid_mailer 包从我的 Pyramid 网站发送电子邮件。首先,如果有人对电子邮件解决方案有其他建议,请告诉我!

我在我的 dev.ini 中添加了以下内容:

mail.host = smtp.gmail.com
mail.username = user@gmail.com
mail.password = password
mail.port = 465
mail.ssl = True

然后我像这样发送消息:

config.registry['mailer'] = Mailer.from_settings(settings)

后来……

mailer = request.registry['mailer']
message = Message(subject="hello world",
sender="admin@mysite.com",
recipients=["someaddress@gmail.com"],
body="hello!")
mailer.send(message)

不幸的是,我得到以下异常:

SMTPServerDisconnected: please run connect() first

我做错了什么?

谢谢!

最佳答案

以下设置对我有用:

# pyramid_mailer
mail.host = smtp.gmail.com
mail.port = 587
mail.username = my.login@gmail.com
mail.password = mypassword
mail.tls = True

你的邮件发送代码似乎和我的一样,所以应该可以。

我还没有尝试过 SSL,但我假设所有类型的 bugaboos 都可能存在。

关于python - 无法使用 pyramid_mailer 和 gmail 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6799146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com