发送 1000+ Django 中的电子邮件
这是我现在的设置:
connection = mail.get_connection()
maillist = []
# my real setup is a little more complex for-loop, but basicly I add all recipients to a list.
for person in object_list:
mail_subject = "Mail subject here"
mail_body = "Mail body text...bla bla"
email_sender = "[email protected]"
maillist.append((mail_subject, mail_body, email_sender, [person.email]))
#send_mass_mail wants a tuple, so we convert the list
mailtuple = tuple(maillist)
mail.send_mass_mail(mailtuple, fail_silently=False, connection=connection)
但是,forloop 迭代超过 1000 个对象/人,当我尝试此方法时,我能够发送 101 封电子邮件,然后它停止了。任何地方都没有错误(正如我所看到的)。
一位开发人员提到也许 POST 大小太大? SO 社区有什么想法吗?
Here is my setup right now:
connection = mail.get_connection()
maillist = []
# my real setup is a little more complex for-loop, but basicly I add all recipients to a list.
for person in object_list:
mail_subject = "Mail subject here"
mail_body = "Mail body text...bla bla"
email_sender = "[email protected]"
maillist.append((mail_subject, mail_body, email_sender, [person.email]))
#send_mass_mail wants a tuple, so we convert the list
mailtuple = tuple(maillist)
mail.send_mass_mail(mailtuple, fail_silently=False, connection=connection)
However, the forloop iterates over 1000+ objects/persons and when I try this method I'm able to send 101 emails, and then it stops. No errors (as I can see) anywhere.
A fellow developer mentioned that maybe the POST size was too big? Any ideas from the SO-community?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的 SMTP 服务器可能有一些发送限制。例如,我认为 Gmail 将外发邮件限制为 100 个收件人。
Your SMTP server probably has some send limits. For example, I believe Gmail limits outgoing mail to 100 recipients.
正如 Micah 所建议的,您很可能会达到服务器限制。
一般来说,在处理群发邮件时,限制发送总是一个好主意。由于许多实际原因(包括 smtp 服务器限制),在 300 秒内每 5 秒处理 50 封邮件胜过一次处理 3000 封邮件。
As Micah suggested, there is a good chance you are hitting server limits.
Generally, when dealing with mass mail, it is always a good idea to throttle the sending. Doing 50 mails every 5 seconds for 300 seconds beats 3000 mails at once for many practical reasons including smtp server limitations.
既然您提到了 POST 限制 - 您是否在视图中发送电子邮件?我想知道您如何处理设置中取消的请求。
我正在使用管理命令发送 1000 多份新闻通讯。但我在循环中使用普通的发送方法,而不是 send_mass_mail 。发送邮件大约需要 5 分钟(没有正确的计数 atm),而且我还没有遇到任何服务器限制。
我的计划是切换到 celery 来处理通过网络界面的发送。如果您还没有看过的话,也许您想看一下。
http://celeryproject.org/
Since you mentioned a POST limit - do you send out the emails in a view? I'm wondering how you handle canceled requests in your setup.
I'm using a management command to send out 1000+ newsletters. But instead of send_mass_mail i use the normal send method in a loop. It takes about 5 minutes (haven't a correct count atm) to send out the mails and i haven't run into any server limits yet.
My plan is to switch to celery to handle sending through a web interface. Perhaps you want to have a look at it in case you haven't already.
http://celeryproject.org/