Skip to content

Commit

Permalink
Sendinblue: method to send transactional email with html
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Jun 23, 2023
1 parent 9928280 commit b07f519
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions core/utils/sendinblue.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ def newsletter_registration(user_email):


def send_transactional_email_with_template_id(
template_id,
to_email,
to_name,
template_id,
parameters=None,
from_email=settings.DEFAULT_FROM_EMAIL,
from_name=settings.DEFAULT_FROM_NAME,
):
data = {
"sender": {"email": from_email, "name": from_name}, # must be a sender registered and verified in Brevo
"sender": {"email": from_email, "name": from_name}, # email must be a sender registered and verified in Brevo
"to": [{"email": to_email, "name": to_name}],
"templateId": template_id,
}
Expand All @@ -83,3 +83,28 @@ def send_transactional_email_with_template_id(
else:
print("Sendinblue: email not sent (DEBUT or TESTING environment detected)")
return True


def send_transactional_email_with_html(
to_email,
to_name,
subject,
html,
parameters=None,
from_email=settings.DEFAULT_FROM_EMAIL,
from_name=settings.DEFAULT_FROM_NAME,
):
data = {
"sender": {"email": from_email, "name": from_name}, # email must be a sender registered and verified in Brevo
"to": [{"email": to_email, "name": to_name}],
"subject": subject,
"htmlContent": html,
}
if parameters:
data["params"] = parameters

if not settings.DEBUG and not settings.TESTING:
return requests.post(settings.SIB_SMTP_ENDPOINT, headers=HEADERS, data=json.dumps(data))
else:
print("Sendinblue: email not sent (DEBUT or TESTING environment detected)")
return True

0 comments on commit b07f519

Please sign in to comment.