Benjamin Dell
Benjamin Dell

Reputation: 3041

Is there a chance that sending an email via a thread could ever fail to complete?

I have a project where I send a couple of emails via a separate thread, to speed up the process for the end user. It works successfully, but I was just wondering whether there were any pitfalls that I might not have considered? My greatest fear is that the user clicks a button, it says that the message has been sent (as it will have been sent to the thread for sending) but for some reason the thread might fail to send it. Are there any situations where a thread could be aborted prematurely?

Please note that I am not talking about network outages or obvious issues with an email recipient not existing. For simplicity's sake please assume that the connection is up, the mail server alive and the recipient valid. Is it possible, for example, for the thread to abort prematurely if the user kills the browser before the thread has completed?

This might be a silly question, but i just wanted to make sure i knew the full ramifications of using a thread in this manner. Thanks, in advance, for your help.

Upvotes: 0

Views: 142

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 599630

Rather than doing it in a thread, you might consider putting messages in a queue and using an external cron job to send them. django-mailer manages this completely transparently.

Upvotes: 1

Guillaume
Guillaume

Reputation: 18865

Killing the HTTP connection should not kill your email thread. But of course, as you noticed, a lot of things could go wrong with sending an email (SMTP server down, network outage, bug in your code, ...).

Upvotes: 0

Related Questions