我如何知道电子邮件是否在 Plone 上正确发送? '返回主机.send(mail_text)'总是返回 None
遵循 Plone 社区管理的开发人员文档发送电子邮件:
try:
host = getToolByName(self, 'MailHost')
return host.send(mail_text)
except SMTPRecipientsRefused:
# Don't disclose email address on failure
raise SMTPRecipientsRefused('Recipient address rejected by server')
...但是 return host.send(mail_text)
始终返回 None
,无论电子邮件是否已发送(电子邮件实际上正在发送) 。那么,我是否可以假设如果结果是 None
,那么它就成功了?我觉得这不对。有什么想法吗?
Following the Plone community-managed developer docs about sending e-mail:
try:
host = getToolByName(self, 'MailHost')
return host.send(mail_text)
except SMTPRecipientsRefused:
# Don't disclose email address on failure
raise SMTPRecipientsRefused('Recipient address rejected by server')
...but return host.send(mail_text)
always returns None
, regardless if the email was sent or not (the email is being sent actually). So, can I assume if None
is the result, it was successfull? This doesn't seen right to me. Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Python 有异常,因此不需要返回状态代码来指示失败。 (对于 C/Unix,返回码 0 表示成功,布尔 true 值表示错误。)
如果您需要在代码中对邮件失败做出反应,则必须在代码中包含
immediate=True
参数,否则邮件将在事务边界发送并可能排队。然后您可以使用 try/ except 捕获异常。Python has exceptions so does not need to return a status code to indicate a failure. (With C/Unix a return code of 0 indicates success, a boolean true value indicates an error.)
If you need to react to a mail failure in your code, you must include
immediate=True
in the parameters, otherwise the mail will be sent at the transaction boundary and possibly queued. You can then catch an exception using try/except.该代码假设发送有效,除非引发异常
That code assumes the send works unless an exception is raised