[英]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. 因此,可以说用户x在网站上向用户y发送了一条消息。 User y is notified on the website, but it doesn't get any email about this. 用户y在网站上得到通知,但没有收到有关此电子邮件。
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. 我想解决的唯一一件事是在用户x向用户y发送消息的代码之后粘贴一些代码以向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? 您将如何处理?
For performance, you can use django-mailer . 为了提高性能,您可以使用django-mailer 。 django-mailer provides an email backend that queues emails rather than sending it directly. django-mailer提供了一个电子邮件后端,该后端将电子邮件排队,而不是直接发送。 Emails are then sent by a cron job which you should setup, running manage.py send_mail
. 然后, 由您应该设置的cron作业 (运行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. 另外,您可能想使用django-notification应用程序,它具有用于通知电子邮件的漂亮模式+为用户提供了查看/取消选中他/她希望/不希望通过电子邮件获取的通知类型的视图。
Creating a post_save signal to send the email after the message has been saved to the model would be one solution. 一种解决方案是创建一个post_save信号以在将消息保存到模型后发送电子邮件。 Although for performance an email queue solution would be recommended. 尽管为了提高性能,建议使用电子邮件队列解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.