def _create(cls, email_message, commit=True):
"""A factory method creates model from a base django EmailMultiAlternatives instance."""
assert email_message.recipients()
instance = cls()
instance.encoding = email_message.encoding or settings.DEFAULT_CHARSET
instance.from_email = email_message.from_email
instance.to = EMAIL_ADDRESS_SEPARATOR.join(email_message.to)
instance.cc = EMAIL_ADDRESS_SEPARATOR.join(email_message.cc)
instance.bcc = EMAIL_ADDRESS_SEPARATOR.join(email_message.bcc)
instance.reply_to = EMAIL_ADDRESS_SEPARATOR.join(email_message.reply_to)
instance.subject = email_message.subject
instance.body_text = email_message.body
for content, mime_type in email_message.alternatives:
if mime_type != HTML_MIME_TYPE:
msg = "Only '{}' mime type is supported, can not send a message with {} alternative"
msg.format(HTML_MIME_TYPE, mime_type)
raise NotImplementedError(msg)
instance.body_html = content
if commit:
instance.save()
return instance
评论列表
文章目录