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 raisemailer.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
- Don't defer messages with non-retryable errors. If sending a message raises a "non-retryable" error, delete the Message from the queue, and note the error in the MessageLog with a new `RESULT_ERROR` ... — committed to medmunds/django-mailer by medmunds 8 years ago
- Fix queue stall on unexpected send error. [NOT FOR MERGE yet: see "TODO" for discussion] In engine.send_all: * Handle transient connection issues by logging error and cleanly exiting send_all. (P... — committed to medmunds/django-mailer by medmunds 8 years ago
- Clean up send error handling; fix stalled send queue. [NOT FOR MERGE yet: see "TODO" comments for discussion] In engine.send_all: * Handle transient connection issues by logging failure and clean... — committed to medmunds/django-mailer by medmunds 8 years ago
- Fixing #73 the hard way — committed to DemokratieInBewegung/django-mailer by gnunicorn 7 years ago
- Merge pull request #133 from hartwork/issue-73-introduce-delivery-error-handler Introduce delivery error handler (related to #73 and #127) — committed to pinax/django-mailer by spookylukey 4 years ago
@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:
Fixed via #133