def send(self, object_or_list):
"""
Given an object_or_list creates a EmailMultiAlternatives and
send it to the respective destination.
If Attachments exist, also adds them to the messsage.
"""
html_as_string = self.render()
text_part = strip_tags(html_as_string)
to = self.get_mail_to(object_or_list)
if to:
msg = EmailMultiAlternatives(
self.get_subject(),
text_part,
self.get_mail_from(),
to=to,
cc=self.get_mail_cc(),
bcc=self.get_mail_bcc(),
reply_to=self.get_mail_reply_to())
# Attach the html version of email
msg.attach_alternative(html_as_string, "text/html")
# If there is attachments attach them to the email
for attachment in self.get_attachments():
msg.attach(*attachment.get_triple())
return get_connection().send_messages([msg])
return 0
评论列表
文章目录