Example #1
0
def email_react_rendered_content_with_attachment(
    site_type: str,
    user: JustfixUser,
    url: str,
    recipients: List[str],
    attachment: FileResponse,
    locale: str,
    is_html_email: bool = False,
    headers: Optional[Dict[str, str]] = None,
) -> None:
    """
    Renders an email in the front-end, using the given site and locale,
    and sends it to the given recipients with the given attachment.
    """

    email = react_render_email(
        site_type,
        locale,
        url,
        user=user,
        is_html_email=is_html_email,
    )
    email_file_response_as_attachment(
        subject=email.subject,
        body=email.body,
        html_body=email.html_body,
        recipients=recipients,
        attachment=attachment,
        headers=headers,
    )
Example #2
0
def email_packet(user_id: int, recipients: List[str]) -> None:
    user = JustfixUser.objects.get(pk=user_id)
    email_file_response_as_attachment(
        subject=f"{user.full_name}'s HP Action packet",
        body=
        (f"{get_site_name()} here! Attached is a copy of {user.full_name}'s HP Action packet, "
         f"which {user.first_name} requested we send you."),
        recipients=recipients,
        attachment=get_latest_pdf_for_user(user))
Example #3
0
def email_letter(user_id: int, recipients: List[str]) -> None:
    user = JustfixUser.objects.get(pk=user_id)
    request = HttpRequest()
    SessionMiddleware().process_request(request)
    email_file_response_as_attachment(
        subject=f"{user.full_name}'s letter of complaint",
        body=
        (f"{get_site_name()} here! Attached is a copy of {user.full_name}'s letter of "
         f"complaint, which {user.first_name} requested we send you."),
        recipients=recipients,
        attachment=render_letter_of_complaint(request, user, 'pdf'))
 def test_it_works_with_html_body(self, mailoutbox):
     email_file_response_as_attachment(
         subject="here is subject",
         body="here is body",
         html_body="<p>here is html body</p>",
         recipients=["*****@*****.**", "*****@*****.**"],
         attachment=FileResponse(BytesIO(b"hi"), filename="hello.txt"),
     )
     assert len(mailoutbox) == 2
     msg = mailoutbox[0]
     assert msg.body == "here is body"
     assert msg.alternatives == [("<p>here is html body</p>", "text/html")]
 def test_it_works_without_html_body(self, mailoutbox):
     email_file_response_as_attachment(
         subject="here is subject",
         body="here is body",
         recipients=["*****@*****.**", "*****@*****.**"],
         attachment=FileResponse(BytesIO(b"hi"), filename="hello.txt"),
     )
     assert len(mailoutbox) == 2
     msg = mailoutbox[0]
     assert msg.subject == "here is subject"
     assert msg.body == "here is body"
     assert len(msg.attachments) == 1
     assert msg.attachments[0] == ("hello.txt", "hi", "text/plain")
     assert msg.recipients() == ["*****@*****.**"]
     assert mailoutbox[1].recipients() == ["*****@*****.**"]
     assert msg.alternatives == []