Skip to content

[Question] Handling email backend exceptions #246

Description

@1oglop1

Hi, thank you for this project it saved me a lot of time!
I have a question about handling exceptions from Anymail and generally any e-mail backend.

My function sends an e-mail:

from django.core.mail import EmailMessage

def dummy():
     email = EmailMessage(
        "subject",
        "body",
        "from@example.com"
        ["to@example.com"],
    )
    email.send()

Is there any general way to catch the exception from email backends other than using broad Exception?
By default Django raises smtplib.SMTPError and anymail has AnymailAPIError.

This would mean that for each email backend I'd have to add its exception in the test:

try:
  email.send()
except SMTPException,AnymailAPIError :
   pass # do something useful

I noticed there was once a proposal for this https://code.djangoproject.com/ticket/23944
I'm wondering if anyone is aware of any development in the Django ecosystem since I'm pretty new to Django.
Even though it's highly unlikely I'll be changing the email backend, I'm still interested in the answer.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions