Send a django.core.mail.EmailMultiAlternatives to `to_email`.
(
self,
subject_template_name,
email_template_name,
context,
from_email,
to_email,
html_email_template_name=None,
)
| 392 | ) |
| 393 | |
| 394 | def send_mail( |
| 395 | self, |
| 396 | subject_template_name, |
| 397 | email_template_name, |
| 398 | context, |
| 399 | from_email, |
| 400 | to_email, |
| 401 | html_email_template_name=None, |
| 402 | ): |
| 403 | """ |
| 404 | Send a django.core.mail.EmailMultiAlternatives to `to_email`. |
| 405 | """ |
| 406 | subject = loader.render_to_string(subject_template_name, context) |
| 407 | # Email subject *must not* contain newlines |
| 408 | subject = "".join(subject.splitlines()) |
| 409 | body = loader.render_to_string(email_template_name, context) |
| 410 | |
| 411 | email_message = EmailMultiAlternatives(subject, body, from_email, [to_email]) |
| 412 | if html_email_template_name is not None: |
| 413 | html_email = loader.render_to_string(html_email_template_name, context) |
| 414 | email_message.attach_alternative(html_email, "text/html") |
| 415 | |
| 416 | try: |
| 417 | email_message.send() |
| 418 | except Exception: |
| 419 | logger.exception( |
| 420 | "Failed to send password reset email to %s", context["user"].pk |
| 421 | ) |
| 422 | |
| 423 | def get_users(self, email): |
| 424 | """Given an email, return matching user(s) who should receive a reset. |
no test coverage detected