无法使用金字塔邮件程序和 gmail 发送电子邮件
我正在尝试使用我的 gmail smtp 和金字塔邮件程序包从我的金字塔网站发送电子邮件。首先,如果有人对电子邮件解决方案有其他建议,请告诉我!
我将以下内容添加到我的 dev.ini:
mail.host = smtp.gmail.com
mail.username = [email protected]
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="[email protected]",
recipients=["[email protected]"],
body="hello!")
mailer.send(message)
不幸的是,我收到以下异常:
SMTPServerDisconnected: please run connect() first
我做错了什么?
谢谢!
I am trying to send emails from my pyramid website with my gmail smtp and the pyramid_mailer package. First of all, if anyone has another suggestion for an email solution, please let me know!
I added the following to my dev.ini:
mail.host = smtp.gmail.com
mail.username = [email protected]
mail.password = password
mail.port = 465
mail.ssl = True
And then I'm sending the message like so:
config.registry['mailer'] = Mailer.from_settings(settings)
and later...
mailer = request.registry['mailer']
message = Message(subject="hello world",
sender="[email protected]",
recipients=["[email protected]"],
body="hello!")
mailer.send(message)
Unfortunately, I get the following exception:
SMTPServerDisconnected: please run connect() first
What am I doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下设置对我有用:
您的邮件发送代码似乎与我的相同,因此应该可以工作。
我还没有尝试过 SSL,但我假设可能存在各种错误。
The following settings worked for me:
Your mail sending code seems to be the same as mine, so that should work.
I haven't tried SSL, but I'm assuming that all kinds of bugaboos may exist thataway.
直到交易提交后,电子邮件才会真正发送。
您应该提交事务:
或使用 send_immediately:
The email is not actually sent until the transaction is committed.
You should commit the transaction:
or use send_immediately: