From b07f519cba9ee97c5ab3400043a109cc46b48866 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Fri, 23 Jun 2023 20:36:56 +0200 Subject: [PATCH] Sendinblue: method to send transactional email with html --- core/utils/sendinblue.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/core/utils/sendinblue.py b/core/utils/sendinblue.py index 637b1a7a..56a0efbf 100644 --- a/core/utils/sendinblue.py +++ b/core/utils/sendinblue.py @@ -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, } @@ -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