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 substan开发者_如何学运维tial performance overhead to send one email at time?
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.
精彩评论