跳转到主要内容

为singing dancing记录SMTP错误的补丁

项目描述

一个简单而愚蠢的singing dancing覆盖

如果抛出STMTP异常,进程队列会停止,但分发没有注意到这一点。

http://svn.plone.org/svn/collective/collective.singing/trunk/collective/singing/message.py中,由于zope.sendmail的结构,在该情况下try,catch不起作用。我猜collective.dancing.composer.SMTPMailer.send在这种情况下必须有try ... except。smtplib中的异常有

“SMTPException”, “SMTPServerDisconnected”, “SMTPResponseException”, “SMTPSenderRefused”, “SMTPRecipientsRefused”, “SMTPDataError”, “SMTPConnectError”, “SMTPHeloError”, “SMTPAuthenticationError”,

“SMTPRecipientsRefused”和“SMTPSenderRefused”不是分发过程的临界错误,我认为它们可以在SMTPMailer中被捕获。在我的情况下,由于空电子邮件地址导致的队列失败,收件人收到了同一份新闻简报的数百条消息。队列从未被清除,@@dancing.utils/tick_and_dispatch通过阻塞zope服务器结束。

跟踪信息

INFO collective.singing Dispatching is locked by another process.

CRITICAL txn.16292 A storage error occurred during the second phase of the
two-phase commit.  Resources may be in an inconsistent state.

2009-05-25T09:48:09 ERROR Zope.SiteErrorLog
.../@@dancing.utils/tick_and_dispatch

Traceback (innermost last):

 Module ZPublisher.Publish, line 125, in publish

 Module Zope2.App.startup, line 238, in commit

 Module transaction._manager, line 96, in commit

 Module transaction._transaction, line 395, in commit

 Module transaction._transaction, line 503, in _commitResources

 Module zope.sendmail.delivery, line 87, in tpc_finish

 Module collective.dancing.composer, line 376, in send

 Module zope.sendmail.mailer, line 72, in send

 Module smtplib, line 695, in sendmail

SMTPRecipientsRefused: {}

因此,这个egg的目标就是避免这种情况!!

>>> from zope.component import getUtility
>>> from zope.sendmail.mailer import ISMTPMailer
>>> utility = getUtility(ISMTPMailer, name= 'patchplone.smtp')
>>> utility
<patch.singingdancing.composer.SMTPMailer...>

提供smtplib的简单补丁

>>> from zope.sendmail.mailer import SMTPMailer
>>> from smtplib import SMTPRecipientsRefused
>>> from smtplib import SMTPSenderRefused
>>> def new_send(self, from_addr, to_addrs, msg):
...    if to_addrs == ['toto@host.com']:
...        raise SMTPSenderRefused(500, 'failed',to_addrs)
...    elif to_addrs == []:
...        raise SMTPRecipientsRefused(to_addrs)
...    else:
...        return {}

>>> SMTPMailer.send = new_send

现在测试函数

>>> utility.send('y.boussard@ingeniweb.com',['y.boussard@free.fr',],'')
{}
>>> utility.send('y.boussard@ingeniweb.com',['toto@host.com',],'')
{'toto@host.com':...}
>>> utility.send('y.boussard@ingeniweb.com',[],'')
{'y.boussard@ingeniweb.com':...}

更改日志

1.0.2

  • 清理了文档中的restructuredtext [glenfant]

1.0.1

  • 添加了z3c.autoinclude感知 [glenfant]

  • 在setup.py中存在未知选项的问题(警告)[glenfant]

1.0

  • 初始发布

项目详情


由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面