def run(self): msg = EmailMultiAlternatives(self.subject, self.body, self.from_email, self.recipient_list, reply_to=[self.reply_to], cc=self.cc) if self.html: msg.attach_alternative(self.html, "text/html") if self.categories: msg.categories = self.categories msg.send(self.fail_silently)
def send_multi_format_email(self, template_prefix, template_ctxt, target_email): subject_file = '{}/{}_subject.txt'.format(self.prefix, template_prefix) txt_file = '{}/{}.txt'.format(self.prefix, template_prefix) html_file = '{}/{}.html'.format(self.prefix, template_prefix) subject = render_to_string(subject_file, template_ctxt).strip() from_email = settings.DEFAULT_EMAIL_FROM to = target_email text_content = render_to_string(txt_file, template_ctxt) html_content = render_to_string(html_file, template_ctxt) reply_to = config('DEFAULT_REPLY_TO', default=None) cc = None if 'team' in template_ctxt.keys(): sanitized_team_name = template_ctxt.get('team').complete_name \ .replace(u"\xe4", "ae").replace(u"\xf6", "oe").replace(u"\xfc", "ue").replace(u"\xdf", "ss") \ .replace(u"\xc4", "Ae").replace(u"\xd6", "Oe").replace(u"\xdc", "Ue") else: sanitized_team_name = None categories = [self.prefix, template_prefix, sanitized_team_name] if template_prefix in ['payment_reminder', 'signup_confirmation']: cc = [config('TEAM_PAYMENT_CC', default=None)] if settings.DEBUG: categories.append('DEBUG') if settings.SEND_EMAIL_ASYNC: EmailThread(subject, text_content, from_email, recipient_list=to, fail_silently=False, html=html_content, reply_to=reply_to, categories=categories, cc=cc).start() else: msg = EmailMultiAlternatives(subject, text_content, from_email, to, reply_to=[reply_to], cc=cc) if html_content: msg.attach_alternative(html_content, "text/html") if categories: msg.categories = categories msg.send()