#23944: Django should use custom exceptions for errors thrown by send_mail
(etc.),
not smtplib.SMTPException
-------------------------------+--------------------------------------
Reporter: jordanreiter | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Mail) | Version: 1.7
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Comment (by jordanreiter):
> If you have ideas on how you would implement this, sketching that out a
bit more would be helpful.
Sure. I was thinking that `django.core.mail.backends.smtp.SMTPException`
et al would subclass ''both'' `django.core.mail.exceptions.EmailError`
''and'' `smtplib.SMTPException`. That way existing code that caught
`smtplib.SMTPException` would behave the same as it does now, but newer
code could catch `EmailException` instead.
I think it's necessary because there are '''tons''' of third party apps
that use `send_mail` and if you write your own backend (or use another
library) then you can run into problems.
Obviously until most apps use `EmailException` they will still fall flat,
but right now it's pretty much enshrined that they will break if you're
using a non-smtplib-based library.
For example, if you use are using Amazon SES (via boto) as the backend,
the exception that comes back is likely to be
`boto.SESConnection.ResponseError`.
Establishing custom exceptions would have two benefits:
- establishing a standard that developers of non-SMTP mail backends can
use when raising exceptions
- decoupling exceptions from the smtp library altogether
I was thinking that the exceptions that would be available in
`django.core.mail.exceptions` would be `EmailError`,
`EmailAuthenticationError`, `EmailConnectError`, `RecipientsRefused`, and
`SenderRefused`. It seems like these are all functions that most backends
would implement and, if they don't, then they wouldn't throw those
exceptions and so they don't need to be implemented for that backend.
For the Amazon SES example, failing to send correct API credentials would
result in `SESAuthenticationError` which subclasses
`EmailAuthenticationError` while encountering a situation where for some
reason the API was failing to respond correctly would result in
`SESConnectError` which subclasses `EmailConnectError`. And so on.
--
Ticket URL: <https://code.djangoproject.com/ticket/23944#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/070.b1acb6eb50dffe9b802bb0d7c403e9b6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.