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 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

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, 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

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 == ['']:
...        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('',['',],'')
>>> utility.send('',['',],'')
>>> utility.send('',[],'')

Changes log


  • Cleaned restructuredtext in docs [glenfant]


  • Added z3c.autoinclude awareness [glenfant]
  • Issue (warning) in unknown option in [glenfant]


  • Initial release

Project details

Release history Release notifications

This version


Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page