如何向Django的10,000个用户发送电子邮件? [英] How does one send an email to 10,000 users in Django?

查看:215
本文介绍了如何向Django的10,000个用户发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Django应用程序有10,000个用户,全部都有电子邮件。我想向他们发送一封电子邮件,每个月说一次。这个消息可能有一些pdf附件。



我试过的是使用一个EmailMessage对象发送一封电子邮件给他们。在发送之前,我将所有用户的电子邮件地址添加到此EmailMessage的密件抄送组件。

  recList = [] 
收件人:
reci = str.strip(str(recipient))
recList.append(reci)
message =(form.cleaned_data ['subject'],form.cleaned_data ['消息'],'emailAdmin@yahoo.com',recList)
mail = EmailMessage(form.cleaned_data ['subject'],form.cleaned_data ['message'],'email_manager@mysite.org',[' email_list@mysite.org'],recList)
num_attachments = 0
如果form.cleaned_data ['attachment']!= None:
email_attachment = EmailAttachment(
document_name = form。 clean_data ['attachment']。name,
email_message = email,
document = form.cleaned_data ['attachment'],

email_attachment.save()
mail.attach_fi le(settings.MEDIA_ROOT +/+ email_attachment.document.name)
mail.send(fail_silently = False)

但是,当我发送电子邮件时,Django抱怨说连接已重置,不发送。我假设服务器连接已关闭。



在Django中发送群发电子邮件的方法是什么? send_mass_mail()更有效?

解决方案

另一个建议:注册邮件服务,并使用他们的API来维护您的电子邮件列表并发送邮件。这种方法有两个优点:




  • 他们会处理任何取消订阅的请求,所以你不必担心添加排除标记给不想要您的电子邮件的用户。

  • 您不太可能将垃圾邮件从您的用户收件箱中过滤掉,或者使您的托管服务提供商烦人。 li>


有一些API包装器,其中包括 MailChimp Campaign Monitor 。在邮件列表中添加新用户应该是相当容易的,如果相关的话删除任何删除其帐户的用户。


My Django application has 10,000 users, all with emails. I would like to send an email message to all of them say once a month. This message could have some pdf attachments.

What I have tried is using an EmailMessage object to send an email to all of them. I add all users' email addresses to the bcc component of this EmailMessage before sending.

        recList = []
        for recipient in rec:
            reci = str.strip(str(recipient))
            recList.append(reci)
            message = (form.cleaned_data['subject'], form.cleaned_data['message'], 'emailAdmin@yahoo.com', recList)
        mail = EmailMessage(form.cleaned_data['subject'], form.cleaned_data['message'], 'email_manager@mysite.org', ['email_list@mysite.org'], recList)
        num_attachments = 0
        if form.cleaned_data['attachment'] != None:
            email_attachment = EmailAttachment(
                document_name = form.cleaned_data['attachment'].name,
                email_message = email,
                document = form.cleaned_data['attachment'],
            )
            email_attachment.save()
            mail.attach_file(settings.MEDIA_ROOT + "/" + email_attachment.document.name)
        mail.send(fail_silently=False)

However, when I send the email, Django complains that "The connection was reset" and does not send. I am assuming that the server connection was closed.

What's an efficient way to send a mass email blast in Django? Would send_mass_mail() be more effective?

解决方案

An alternative suggestion: sign up to a mailing service and use their APIs to maintain your email list and send out mailings. A couple of advantages to this approach:

  • They’ll handle any unsubscribe requests for you, so you don’t have to worry about adding exclusion flags to your users who don’t want your emails.
  • You’re less likely to get spam-filtered out of your users’ inboxes, or to annoy your hosting provider.

There are API wrappers available for, among others, MailChimp and Campaign Monitor. It should be fairly easy to add in hooks to add new users to the mailing list and (if relevant) remove any users who delete their accounts.

这篇关于如何向Django的10,000个用户发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆