marrow / mailer

A light-weight, modular, message representation and mail delivery framework for Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SMTP backend not raising SMTPRecipientsRefused

hyperknot opened this issue · comments

I am trying to send a message with wrong configured sender. I am getting the following line in the log:

2017-02-15 03:28:25,154 WARNI [marrow.mailer.transport.smtp] <148712570228.24873.12356218486855342422@....local> REFUSED SMTPRecipientsRefused {u'...@gmail.com': (550, '5.1.0 <noreply@....com>: Sender address rejected: User unknown in relay recipient table')}

My problem is that nothing else happens. That exception is not raised, just silently logged.

I believe an exception like this should be treated similarly to if a sending couldn't happen for example because of wrong password or something. That one raises an exception, this one does not.

The reason is this line is just silently "eating" all exceptions:

self.send_with_smtp(message)

It's not "eating" exceptions, it's transforming them.

except SMTPRecipientsRefused as e:
# All recipients were refused. Log which recipients.
# This allows you to automatically parse your logs for bad e-mail addresses.
log.warning("%s REFUSED %s %s", message.id, e.__class__.__name__, e)
raise MessageFailedException(str(e))

Admittedly, this folds SMTPSenderRefused and SMTPRecipientsRefused into a single MessageFailedException whose args[0] references the actual exception that occurred. Additionally, it logs a message that should contain sufficient information to identify which recipients were rejected.

This clearly requires an explicit test case.