views:

45

answers:

1

There's a requirement in a web app I'm building about the possibility of the user sending join invitations to his friends. These invitations are stored in the database through the Invitation model. The user can send multiple invitations at once.

What do you think is more appropriate: sending all emails at once in the back end view or sending one at time in Invitation post_save?

Is there a substantial performance overhead to send one email at time?

+5  A: 

If this is live application and user experience is important, then I suggest you avoid sending anything email-related in post_save handlers, or even in views.

Reasons are: SMTP can go down, network connection can go down, network can be up but speed can be that of a snail etc. In each of those cases either your program breaks, or user waits and waits and waits... which is not good for business.

The solution is to write/buy/find separate email dispatcher that is able to handle all such situations gently, alert administrator in case of trouble, switch SMTP gates on the fly, additionally it could trace bounce-back etc.

Then, in your post_save handler, you only add something like this:

   email_dispatcher.add_to_queue(my_email)

Regarding ready-made solutions - quick scan of code.google com resulted in http://code.google.com/p/django-mailer/ but I haven't used it so cannot make recommendation.

Tomasz Zielinski
django-mailer works great. Just remember that all your mail is going into a queue and you have to have some sort of process running that clears said queue. This is documented though.
istruble