views:

26

answers:

2

I have a project where I send a couple of emails via a seperet thread, to speed up the process for the end-user. It works successfully, but i was just wondering whether there were any potfalls 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 simplicites sake please assume that the connect 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.

A: 

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, ...).

Guillaume
A: 

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.

Daniel Roseman