简体   繁体   English

什么是发生事件时通过电子邮件通知用户的最佳方法-Django

[英]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.

相关问题 用Django实现配置应用的最佳方法是什么? - What is the best approach to implement configuration app with Django? Django - 处理多种用户类型的最佳方法是什么……并基于此路由 HTML 页面? - Django - What is the best approach to handle multiple user types…and route the HTML pages based on this? 为人脸识别存储每个人的多个向量的最佳方法是什么 - What is the best approach for storing multiple vectors per person for face recognition 解决与每部分累积总和相关的问题的最佳方法是什么? - What is the best approach to this issue related to cumulative sum per section? 在 django 中创建用户时自动创建配置文件 object 的最佳方法 - Best approach to auto create profile object upon user creation in django 在Django项目中使用Web套接字的最佳方法是什么? - What is the best approach to use Web Sockets with Django projects? 下一步取决于Django的最后一步的最佳方法是什么? - what is the best way to approach where next is depending on last step in django? 设计模型字段(如Django中的列表)的最佳方法是什么? - What is the best approach to design model fields that is like a list in Django? 在现有 Django 应用程序中更改主键的最佳方法是什么? - What is the best approach to change primary keys in an existing Django app? Django-Postman禁用每个用户的电子邮件通知 - Django-Postman disable email notification per user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM