记录smtp错误的歌舞补丁
patch.singingdancing的Python项目详细描述
唱歌跳舞的简单而愚蠢的替代方法
如果引发了stmtp异常,进程队列将停止,但调度不会 请注意。
在 http://svn.plone.org/svn/collective/collective.singing/trunk/collective/singing/message.py try,catch在这种情况下不起作用,因为 我想是Zope.Sendmail吧。我认为 collective.dancing.composer.SMTPMailer.send必须有一个try ... except 那样的话。smtplib中的异常是:
“smtpexception”、“smtpserverdisconnected”、“smtpresponseexception”, “smtpsenderrefused”、“smtprecipientsrefused”、“smtpdataerror”, “smtpconnecterror”、“smtpheloerror”、“smtpauthenticationerror”,
SMTPRecipientsRefused和SMTPSenderRefused对于 调度过程,我认为它们可以在SMTPMailer中捕获。在我的 案例中,收件人收到了同一时事通讯的100封邮件,因为 空电子邮件地址的队列失败。队列永远不会被清除, @@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: {}
所以这个蛋的目的就是避免这个!!:
>>> 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
- 清除文档中的重新构造文本 [格伦芬特]
1.0.1
- 增加了z3c.autoinclude感知 [格伦芬特]
- setup.py中未知选项中的问题(警告) [格伦芬特]
1.0
- 初始版本