0

models.py無法發送電子郵件到2個以上的電子郵件地址

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=['[email protected]']) 
      msg.attach_alternative(html_content, "text/html") 
      msg.send() 

以上是我view.py發送電子郵件,電子郵件被髮送到「以「地址正確。問題是與密件抄送標記。我從FollowerEmail表和製作一個列表。我將該列表傳遞給密件抄送,因爲密件抄送電子郵件ID列表將大,將超過3.

如果列表中有超過2個電子郵件ID,摺疊不發送郵件,如果是兩個或一個應用程序發送mail.What可能是問題

感謝

回答

1

你有一個錯字。

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

此時list已經是一個Python list(因爲這是混亂,不是一個好的做法你或許應該重新命名這個變量)。

然後你使用它作爲:

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

而這正是是一個錯字。您正在傳遞一個列表項,而您應該只傳遞一個字符串列表:

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

,它工作....謝謝 –

相關問題