Exceptions in send_mail when fail_silently=True

1.1k views Asked by At

I was going to use send_mail function to send email, and I was hoping that using fail_silently=True would prevent this function from raising exceptions.

It turns out it does work if SMTPException is raised; however I noticed it doesn't intercept socket.error exception - so if STMP server is down, an exception will be raised even with fail_silently=True

I'm now wondering how to get the complete list of exceptions raised by send_mail so I can catch them in try/except loop. Any suggestions?

1

There are 1 answers

0
valignatev On BEST ANSWER

I'd say that catch an Exception is a very final approach. Since both SMTPException and socket.error are children of IOError you can catch an IOError instead. If you'll ever catch something else - you can add this to your catch list later.