如何在 Django 中发送群发邮件并获取每条消息的状态?
我正在创建一个网络应用程序来处理各种调查。管理员可以创建自己的调查并要求用户填写。用户由分配给调查的目标组定义(因此只有调查目标组中的用户才能填写调查)。
定义目标组的方法之一是“令牌目标组”。管理员可以决定生成例如 25 个令牌。之后,任何使用特殊链接(当然包含令牌)的人都可以访问该调查。
现在主要问题是: 每个令牌可能有一个与其自身关联的电子邮件地址。如何安全地发送包含调查访问链接的电子邮件?我可能需要发送几千封电子邮件(我认为最多 10 000 封)。这是一个极端的例子,如此巨大的邮件只是偶尔需要。 但我也希望能够跟踪电子邮件状态(是否已发送或是否有任何错误?)。我还想确保 SMTP 服务器不会阻止此邮件。如果应用程序保持响应,那就太好了:)(任务应该在后台运行)。
处理这个问题的最佳方法是什么?
就我而言,标准的 Django 邮件功能在这里没有多大帮助。人们报告说,建立连接并循环调用 send() 的消息需要很长时间。它不会“在后台”运行,所以我相信这可能会对应用程序响应能力产生负面影响,对吧?
我读过有关 django-mailer 的内容,但据我了解文档 - 它没有允许跟踪消息状态。或者确实如此?
我还有哪些其他选择?
I'm creating a web app for handling various surveys. An admin can create his own survey and ask users to fill it up. Users are defined by target groups assigned to the survey (so only user in survey's target group can fill the survey).
One of methods to define a target group is a "Token target group". An admin can decide to generate e.g. 25 tokens. After that, the survey can be accessed by anyone who uses a special link (containing the token of course).
So now to the main question:
Every token might have an e-mail address associated with itself. How can I safely send e-mails containing the access link for the survey? I might need to send a few thousand e-mails (max. 10 000 I believe). This is an extreme example and such huge mailings would be needed only occasionally.
But I also would like to be able to keep track of the e-mail message status (was it send or was there any error?). I would also like to make sure that the SMTP server doesn't block this mailing. It would also be nice if the application remained responsive :) (The task should run in background).
What is the best way to handle that problem?
As far as I'm concerned, the standard Django mailing feature won't be much help here. People report that setting up a connection and looping through messages calling send() on them takes forever. It wouldn't run "in background", so I believe that this could have negative impact on the application responsiveness, right?
I read about django-mailer, but as far as I understood the docs - it doesn't allow to keep track of the message status. Or does it?
What are my other options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定其余的,但无论任务背景如何(无论你最终如何做),你都会想要寻找 Celery< /a>
Not sure about the rest, but regardless for backgrounding the task (no matter how you eventually do it) you'll want to look for Celery
这里的关键是重用连接并且不要为每封电子邮件再次打开它。 这里是关于该主题的文档。
The key here is to reuse connection and to not open it again for each email. Here is a documentation on the subject.