【问题标题】:what is the best approach to notify per email the user when an event occurs - django发生事件时通过电子邮件通知用户的最佳方法是什么 - django
【发布时间】:2012-03-22 11:51:49
【问题描述】:

假设用户 x 在网站上向用户 y 发送了一条消息。 用户 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

我不知道这种方法在性能方面有多好。

你的想法是什么?您将如何处理?

【问题讨论】:

    标签: python django message


    【解决方案1】:

    为了提高性能,您可以使用django-mailer。 django-mailer 提供了一个电子邮件后端,可以将电子邮件排队而不是直接发送。然后电子邮件是您应该设置的sent by a cron job,运行manage.py send_mail

    另外,您可能想使用django-notification 应用程序,它有一个很好的通知电子邮件模式 + 为用户提供了一个查看/取消选中他/她想要/不想通过的通知类型的视图电子邮件。

    【讨论】:

    • django-notification 看起来很有潜力 :) 会尝试一下,谢谢
    • 任何时候!别忘了close the question
    • 我会在测试应用程序后立即执行此操作,不用担心 :)
    【解决方案2】:

    在消息保存到模型后创建一个 post_save 信号来发送电子邮件是一种解决方案。尽管出于性能考虑,建议使用电子邮件队列解决方案。

    【讨论】:

      猜你喜欢
      • 2020-09-28
      • 2011-05-21
      • 2011-04-10
      • 1970-01-01
      • 2010-12-23
      • 1970-01-01
      • 1970-01-01
      • 2011-07-02
      • 1970-01-01
      相关资源
      最近更新 更多