Send a django.core.mail.EmailMultiAlternatives to `to_email`.
(self, to_email, context)
| 131 | self.send_mail(email, context) |
| 132 | |
| 133 | def send_mail(self, to_email, context): |
| 134 | """Send a django.core.mail.EmailMultiAlternatives to `to_email`.""" |
| 135 | subject = loader.render_to_string(self.subject_template_name, context) |
| 136 | # Email subject *must not* contain newlines |
| 137 | subject = "".join(subject.splitlines()) |
| 138 | body = loader.render_to_string(self.email_template_name, context) |
| 139 | |
| 140 | email_message = EmailMultiAlternatives( |
| 141 | subject, body, self.from_email, [to_email] |
| 142 | ) |
| 143 | try: |
| 144 | template = loader.get_template(self.html_email_template_name) |
| 145 | except TemplateDoesNotExist: |
| 146 | pass |
| 147 | else: |
| 148 | html_email = template.render(context, self.request) |
| 149 | email_message.attach_alternative(html_email, "text/html") |
| 150 | |
| 151 | email_message.send() |
no outgoing calls