def send(self, event, users, instance, paths):
from_address = settings.ASYNC_EMAIL_FROM
reply_to = {}
if hasattr(settings, 'ASYNC_EMAIL_REPLY_TO'):
reply_to = {'Reply-To': settings.ASYNC_EMAIL_REPLY_TO, 'Return-Path': settings.ASYNC_EMAIL_REPLY_TO}
messages = []
for user, templates in users.items():
if not self.enabled(event, user, paths) or not user.email:
continue
template = self._get_template(templates)
if template is None:
continue
params = self.prepare(template, instance)
e = mail.EmailMultiAlternatives(
subject=params['subject'],
body=params['description'],
from_email=from_address,
to=[user.email, ],
headers=reply_to
)
e.attach_alternative(markdown2.markdown(params['description'], extras=["link-patterns"],
link_patterns=link_registry.link_patterns(request), safe_mode=True),
'text/html')
messages.append(e)
if len(messages):
connection = mail.get_connection()
connection.send_messages(messages)
评论列表
文章目录