无法使用金字塔邮件程序和 gmail 发送电子邮件

发布于 2024-11-26 00:00:44 字数 1125 浏览 1 评论 0原文

我正在尝试使用我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美男兮 2024-12-03 00:00:44

以下设置对我有用:

# pyramid_mailer
mail.host = smtp.gmail.com
mail.port = 587
mail.username = [email protected]
mail.password = mypassword
mail.tls = True

您的邮件发送代码似乎与我的相同,因此应该可以工作。

我还没有尝试过 SSL,但我假设可能存在各种错误。

The following settings worked for me:

# pyramid_mailer
mail.host = smtp.gmail.com
mail.port = 587
mail.username = [email protected]
mail.password = mypassword
mail.tls = True

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.

弥繁 2024-12-03 00:00:44

直到交易提交后,电子邮件才会真正发送。

您应该提交事务:

import transaction
transaction.commit()

或使用 send_immediately:

mailer.send_immediately(message, fail_silently=False)

The email is not actually sent until the transaction is committed.

You should commit the transaction:

import transaction
transaction.commit()

or use send_immediately:

mailer.send_immediately(message, fail_silently=False)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文