记录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”,

SMTPRecipientsRefusedSMTPSenderRefused对于 调度过程,我认为它们可以在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

  • 初始版本

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带有字符串的java JNA调用与带有字节[]的java JNA调用的行为不同   java基于键列表获取子映射   重启后永久增加java堆大小?   JavaHTTPS服务器:相互SSL身份验证   java为什么接受接口的方法会拒绝该接口的实现?   片段中的java视图无法应用于()   ms access Java SQL更新命令不工作   java将web服务自动打包和部署到Oracle Application Server 10g   java有没有办法在安卓 studio中为安卓时钟设置多个警报?   位于FTP服务器上的文件上的Java校验和md5   在Java中创建类时遇到问题。有些方法不太确定   java错误:在类chrome\u驱动程序中找不到主方法   通用海图(Javascript\Java)