0

模型.py

class FollowerEmail(models.Model):
    report = models.ForeignKey(Report)
    email = models.CharField('Email', max_length=100)

视图.py

def what(request):

    """"""
    follower = FollowerEmail.objects.filter(report=report)
    list=[]        
    for email in follower:
        list.append(email.email)
    """"""""
     if 'send_email' in request.POST:
            subject, from_email, to = 'Notification',user.email, person.parent_email
            html_content = render_to_string('report/print.html',{'person':person,
                                                                 'report':report,
                                                                 'list':list,
                                                                  }) 
            text_content = strip_tags(html_content) 
            msg = EmailMultiAlternatives(subject, text_content, from_email, [to],bcc=[list], cc=['monKarek@live.com'])
            msg.attach_alternative(html_content, "text/html")
            msg.send()

以上是我发送电子邮件的 view.py,电子邮件正确地发送到“收件人”地址。问题与密件抄送标签有关。我正在从 FollowerEmail 表中获取电子邮件并制作一个列表。我将该列表传递给密件抄送,作为密件抄送电子邮件 ID 列表会很大,超过 3 个。

如果列表有超过 2 个电子邮件 id,应用程序没有发送邮件,如果是两个或一个,应用程序正在发送邮件。可能是什么问题

谢谢

4

1 回答 1

1

你有一个错字。

list=[]        
for email in follower:
    list.append(email.email)

此时list已经是一个 Python list(您可能应该重命名此变量,因为这很容易混淆,而且不是一个好习惯)。

然后你把它用作:

EmailMultiAlternatives(..., bcc=[list], ...)

这就是错字的地方。您正在传递一个带有列表项的列表,而您应该只传递一个字符串列表:

EmailMultiAlternatives(..., bcc=list, ...)
于 2013-06-12T20:19:58.217 回答