Skip to main content

A patch for singing dancing that logs SMTP errors

Project description

A simple and stupid override for singing dancing

if there is an STMTP exception raised the process queue stop but dispatch is not notice of that.

In http://svn.plone.org/svn/collective/collective.singing/trunk/collective/singing/message.py the try, catch doesn’t work in that case because of the architecture of zope.sendmail I guess. I think that collective.dancing.composer.SMTPMailer.send must have a try ... except in that case. Exceptions in smtplib are :

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

SMTPRecipientsRefused and SMTPSenderRefused are not critical error for the dispatch process and I think they can be catch in the SMTPMailer. In my case , recipients received hundred message of the same newsletter because the queue failed of a empty email address. The queue is never purge and the @@dancing.utils/tick_and_dispatch finish by blocking zope server.

The traceback:

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: {}

So the goal of this egg is to avoid that !!:

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

Provide an simple patch to 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

So now test the function:

>>> 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':...}

Changes log

1.0.2

  • Cleaned restructuredtext in docs [glenfant]

1.0.1

  • Added z3c.autoinclude awareness [glenfant]

  • Issue (warning) in unknown option in setup.py [glenfant]

1.0

  • Initial release

Project details


Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page