def send_notification(self, sender, dests, reply_to=None, message_id=None, reference=None, footer=None, subject=None):
messages = []
for dest, dest_name, dest_email in dests:
dest_type = ContentType.objects.get_for_model(dest)
dest, _ = MessageAuthor.objects.get_or_create(author_type=dest_type, author_id=dest.pk)
token = self.token + dest.token + hexdigest_sha256(settings.SECRET_KEY, self.token, dest.token)[:16]
if reply_to:
reply_to_name, reply_to_email = reply_to
reply_to_list = ['%s <%s>' % (reply_to_name, reply_to_email.format(token=token))]
else:
reply_to_list = []
headers = dict()
if message_id:
headers.update({
'Message-ID': message_id.format(id=self.token),
})
if message_id and reference:
headers.update({
'References': message_id.format(id=reference),
})
body = self.content
if footer is not None:
body += footer
messages.append(EmailMessage(
subject=subject or self.subject,
body=body,
from_email='%s <%s>' % sender,
to=['%s <%s>' % (dest_name, dest_email)],
reply_to=reply_to_list,
headers=headers,
))
connection = get_connection()
connection.send_messages(messages)
评论列表
文章目录