marlboro
marlboro

Reputation: 264

what is the best approach to notify per email the user when an event occurs - django

So lets say that user x sends a message to user y on a website. User y is notified on the website, but it doesn't get any email about this.

The only thing that I am thinking of to solve this is to stick some code to send out an email to user y after the code where user x sends the message to user y.

def send_msg(request)
    #request.user sends message to other_user
    #send email to other_user and let him know about his new message

I dont know how good this approach is, in terms of performance.

What are your thoughts? How would you approach this?

Upvotes: 1

Views: 265

Answers (2)

Mikael
Mikael

Reputation: 3236

Creating a post_save signal to send the email after the message has been saved to the model would be one solution. Although for performance an email queue solution would be recommended.

Upvotes: 0

jpic
jpic

Reputation: 33420

For performance, you can use django-mailer. django-mailer provides an email backend that queues emails rather than sending it directly. Emails are then sent by a cron job which you should setup, running manage.py send_mail.

Also, you might want to use django-notification app, it has a nice pattern for notification emails + provides a view for the user to check/uncheck the types of notification he/she wants/doesn't want to get by email.

Upvotes: 1

Related Questions