【问题标题】:BCC all recipients with EmailMultiAlternatives使用 EmailMultiAlternatives 密件抄送所有收件人
【发布时间】:2015-08-27 20:17:06
【问题描述】:

我有这种方法可以用来发送大量电子邮件:

def send_mass_html_mail(datatuple, fail_silently=False, user=None, password=None, connection=None):
    connection = connection or get_connection(username=user, password=password, fail_silently=fail_silently)
    messages = []
    for subject, text, html, from_email, recipient in datatuple:
        message = EmailMultiAlternatives(subject, text, from_email, recipient)
        message.attach_alternative(html, 'text/html')
        messages.append(message)
    return connection.send_messages(messages)

我希望能够密件抄送所有人。也就是说,我不想在收件人中包含每个人的电子邮件,而是想隐藏每个人的电子邮件地址。

我尝试将收件人电子邮件设为空白,并将所有收件人添加到 BCC kwargs,但它仍然将每个人的电子邮件都放在收件人字段中。

def send_mass_html_mail(datatuple, fail_silently=False, user=None, password=None, connection=None):
    connection = connection or get_connection(username=user, password=password, fail_silently=fail_silently)
    messages = []
    for subject, text, html, from_email, recipient in datatuple:
        message = EmailMultiAlternatives(subject, text, from_email, [], bcc=recipient)
        message.attach_alternative(html, 'text/html')
        messages.append(message)
    return connection.send_messages(messages)

我做错了什么?我必须单独发送每封电子邮件吗?

编辑:

我最后只是遍历收件人列表并分别发送电子邮件。我不知道为什么它不起作用,但我不能花几个小时在这上面。它对我有用,因为该应用程序一次最多向 25 人发送电子邮件。

我仍然不知道为什么这不起作用。 EmailMultiAlternatives 是否需要 TO 字段中的某些内容?我查看了EmailMultiAlternativesEmailMessage 源代码,似乎它会在该领域没有任何人的情况下发送电子邮件。我的代码有问题,但我无法确定是什么。

【问题讨论】:

  • 我建议使用mandrill.commailgun.com。这也将允许您发送个性化的电子邮件,而不会让收件人互相看到。我将 mandrill 用于我的时事通讯应用程序,效果很好。
  • 您的代码看起来已经在单独发送每封电子邮件?还是recipient实际上是多个地址?

标签: python django


【解决方案1】:

您使用的是大写密件抄送。它应该是小写的。令我惊讶的是,当前的代码现在发送任何电子邮件。

message = EmailMultiAlternatives(subject, text, from_email, [], bcc=recipient_list)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-22
    • 2015-12-19
    • 1970-01-01
    • 2015-10-10
    • 2012-04-10
    • 2010-10-13
    • 2012-12-23
    • 2014-12-27
    相关资源
    最近更新 更多