Skip to content

Instantly share code, notes, and snippets.

@muendelezaji
Created December 11, 2022 14:28
Show Gist options
  • Save muendelezaji/c7cceabf4e73f29a8ab4447cc5d960c7 to your computer and use it in GitHub Desktop.
Save muendelezaji/c7cceabf4e73f29a8ab4447cc5d960c7 to your computer and use it in GitHub Desktop.

Revisions

  1. muendelezaji created this gist Dec 11, 2022.
    26 changes: 26 additions & 0 deletions diff_email_body.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    # 1. Create dynamic body depending on status
    if user_status == "paid":
    body = f"Hello paid user: {user.first_name} {user_status}"
    else:
    body = f"Hello not paid user: {user.first_name} {user_status}"

    # 2. Add it to recipient email substitutions
    to_emails.append(
    To(
    email=user.user_email,
    name=user.first_name,
    substitutions={"-user_email-": user.user_email, "-email_body-": body},
    subject=f"Subject Goes Here {user.first_name}",
    )
    ),

    # 3. Create a mail object with that substituted content
    html_body = "<h1> -email_body- </h1>"
    message = Mail(
    from_email=("[email protected]", "Tenda Mpya"),
    to_emails=to_emails,
    html_content=html_body,
    plain_text_content="Tenders posted today",
    is_multiple=True,
    )