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?
I'd say that catch an
Exception
is a very final approach. Since bothSMTPException
andsocket.error
are children ofIOError
you can catch anIOError
instead. If you'll ever catch something else - you can add this to your catch list later.