def send(self, connection=None, fail_silently=False):
if connection is None:
from django.core.mail import get_connection
connection = get_connection(
backend=settings.EMAIL_QUEUE_EMAIL_BACKEND,
fail_silently=fail_silently
)
to = self.to.split(EMAIL_ADDRESS_SEPARATOR) if self.to and self.to.strip() else None
cc = self.cc.split(EMAIL_ADDRESS_SEPARATOR) if self.cc and self.cc.strip() else None
bcc = self.bcc.split(EMAIL_ADDRESS_SEPARATOR) if self.bcc and self.bcc.strip() else None
mail = EmailMultiAlternatives(
subject=self.subject,
body=self.body_text,
from_email=self.from_email,
to=to,
cc=cc,
bcc=bcc,
connection=connection
)
if self.body_html:
mail.attach_alternative(self.body_html, HTML_MIME_TYPE)
mail.send(fail_silently=fail_silently)
self.posted = timezone.now()
self.status = QueuedEmailMessageStatus.posted
self.save()
logging.debug("Message posted: %s", self)
return mail
评论列表
文章目录