如何在Django中发送大量邮件并获取每个消息的状态?

时间:2021-01-15 00:23:51

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).

我正在创建一个用于处理各种调查的web应用程序。管理员可以创建自己的调查,并要求用户填写它。用户由分配给调查的目标组定义(因此只有调查的目标组中的用户才能填写调查)。

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).

定义目标组的方法之一是“令牌目标组”。管理员可以决定生成25个令牌。之后,任何使用特殊链接(当然包含令牌)的人都可以访问该调查。

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).

现在主要的问题是:每个令牌都可能有一个与自身关联的电子邮件地址。如何安全地发送包含调查访问链接的电子邮件?我可能需要发送几千封电子邮件(max)。000我相信)。这是一个极端的例子,如此巨大的邮件只是偶尔需要。但我也希望能够跟踪电子邮件消息的状态(它发送了还是有错误?)我还希望确保SMTP服务器不会阻塞此邮件。如果应用程序保持响应性也很好:)(任务应该在后台运行)。

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?

就我而言,标准的Django邮件功能在这里并没有多大帮助。人们报告说,建立一个连接并通过调用send()的消息进行循环需要花费很长时间。它不会“在后台”运行,所以我认为这会对应用程序响应性产生负面影响,对吗?

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?

我读过有关django-mailer的文章,但就我对文档的理解而言,它不允许跟踪消息的状态。还是它?

What are my other options?

我还有其他的选择吗?

2 个解决方案

#1


1  

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

其余的不确定,但是不管你是如何完成任务的,你都要找芹菜

#2


0  

The key here is to reuse connection and to not open it again for each email. Here is a documentation on the subject.

这里的关键是重用连接,并且不要在每次邮件中打开它。这是关于这个主题的文件。

#1


1  

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

其余的不确定,但是不管你是如何完成任务的,你都要找芹菜

#2


0  

The key here is to reuse connection and to not open it again for each email. Here is a documentation on the subject.

这里的关键是重用连接,并且不要在每次邮件中打开它。这是关于这个主题的文件。