views.py
if 'send_email' in request.POST:
subject, from_email, to = 'Parent Incident Notification',user.email, person.parent_email
html_content = render_to_string('incident/print.html',{'person':person,
'report':report,
})
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
上面是发送电子邮件的视图。通过这种方式,我可以将 html 内容与邮件一起发送,它将电子邮件发送到 [to] 地址,我想再做一个密件抄送和抄送。我经历了Emailmessage objects
在文档中。我不知道如何包括密件抄送和抄送来改变我的观点。
需要帮助。
谢谢
EmailMultiAlternatives
是EmailMessage
的子类。您可以在初始化消息时指定bcc
和cc
。
msg = EmailMultiAlternatives(subject, text_content, from_email, [to_email], bcc=[bcc_email], cc=[cc_email])
EmailMessage
now supportscc
andbcc
:
https://docs.djangoproject.com/en/1.10/topics/email/#django.core.mail.EmailMessage
我需要 bcc 与 HTML 内容作为主体,这里是我的实现
from django.core.mail import EmailMessage
email = EmailMessage(
'Subject',
'htmlBody',
'from@email.com',
[to@email.com],
[bcc@email.com],
reply_to=['reply_to@email.com']
)
email.content_subtype = "html"
email.send(fail_silently=True)
有关更多详细信息,请参考Django docs
您可以使用 TextField
class (models.Model):
bcc = models.TextField(null=True, blank=True)
像这样输入多个电子邮件(bcc字段):test1 @ example.com,test2 @ example.com
from django.core.mail import EmailMessage
clients= .objects.all()
for client in clients:
subject = client.subject
content = client.body
contact_email = client.msg_from
to = client.msg_to
bcc_mails = client.bcc
bcc = bcc_mails.split(",")
bcc_mails.replace('"', "")
email = EmailMessage(
subject,
content,
contact_email,
[to],
bcc,
headers={'Reply-To': contact_email}
)
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(26条)