【问题标题】:Not able to send email to more than 2 email address无法向超过 2 个电子邮件地址发送电子邮件
【发布时间】:2013-06-12 19:34:12
【问题描述】:

models.py

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

views.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个。

如果列表有两个以上的电子邮件ID,应用程序没有发送邮件,如果是两个或一个,应用程序正在发送邮件。可能是什么问题

谢谢

【问题讨论】:

    标签: django django-models django-forms django-templates django-views


    【解决方案1】:

    你有一个错字。

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

    此时 list 已经是 Python list (您可能应该重命名此变量,因为这会造成混淆并且不是一个好的做法)。

    然后你将它用作:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      • 1970-01-01
      • 1970-01-01
      • 2011-02-24
      • 2017-03-01
      • 1970-01-01
      • 2013-01-25
      相关资源
      最近更新 更多