django-mailer: Queue stalls when non-SMTP email backend raises error

I’m using django-mailer with a django-anymail backend (specifically, MAILER_EMAIL_BACKEND = "anymail.backends.postmark.PostmarkBackend").

Anymail is not based on smtplib, so it raises its own exceptions for rejected recipients or other errors. Because django-mailer is looking for specific SMTP exceptions, an Anymail exception ends up stalling the queue, rather than deferring the unsendable message. (The exception aborts the send_mail management command, leaving the unsendable message at the top of the prioritization list for the next send.)

What would be a reasonable way to solve this? (I maintain django-anymail, btw.)

  • I don’t think it makes sense to add Anymail-specific exceptions to django-mailer. (Because that starts down the slippery slope to adding specific code for all other email backends.)
  • django-mailer could define and catch its own SendMailException (e.g.), in addition to the current SMTP exceptions. Then other packages that want to play nice with django-mailer could raise mailer.SendMailException when django-mailer is installed. (I’m not at all opposed to adding this to Anymail. But it would sort of start the opposite slippery slope, where email backends need to add specific code for any likely queueing wrappers.)
  • django-mailer’s send_all could just catch Exception, rather than specific SMTP exceptions. I realize broad catch statements are generally a bad idea, but this seems like a case where it might be appropriate.

Thoughts? I’m happy to submit a PR if one of the django-mailer changes makes sense.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 27 (23 by maintainers)

Commits related to this issue

Most upvoted comments

@volksman @hartwork Thanks so much for your work on this, and your patience over a long period of time. There isn’t anyone else apart from me with merge permissions, apart from maybe Pinax people but they don’t contribute here. I confess I’m lacking seriously lacking time and energy for open source work in general, and I’m struggling to remember all the backwards and forwards on this issue. So here’s what I’ll do:

  • I’d like to see a clear section in the docs about the whole error handling strategy, with clear docs about the new settings. Also a note in the changelog with particular attention to any backwards incompatibilities
  • I’ll defer to your judgement since you’ve been doing all the hard work on this, and some solution would be better than we what have at the moment. So, once you two have consensus that the work is done, I’ll merge the PR.

Fixed via #133