From 867e0b0ae035fa1ace4a76e7c28ec940bbf29c24 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Tue, 9 Jan 2024 15:36:19 +0100 Subject: [PATCH] Emails: send email directly from TemplateTransactional object --- lemarche/conversations/models.py | 24 ++++++++++++++++++++++++ lemarche/utils/apis/api_mailjet.py | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lemarche/conversations/models.py b/lemarche/conversations/models.py index 8c8249253..5edf630b1 100644 --- a/lemarche/conversations/models.py +++ b/lemarche/conversations/models.py @@ -10,6 +10,7 @@ from shortuuid import uuid from lemarche.conversations import constants as conversation_constants +from lemarche.utils.apis import api_brevo, api_mailjet class ConversationQuerySet(models.QuerySet): @@ -235,3 +236,26 @@ def get_template_id(self): elif self.source == conversation_constants.SOURCE_BREVO: return self.brevo_id return None + + def send_transactional_email(self, recipient_email, recipient_name, variables): + print("send_transactional_email", self.source) + if self.source == conversation_constants.SOURCE_MAILJET: + api_mailjet.send_transactional_email_with_template( + template_id=self.get_template_id, + subject=self.email_subject, + recipient_email=recipient_email, + recipient_name=recipient_name, + variables=variables, + # from_email=self.email_from_email, + # from_name=self.email_from_name, + ) + elif self.source == conversation_constants.SOURCE_BREVO: + api_brevo.send_transactional_email_with_template( + template_id=self.get_template_id, + subject=self.email_subject, + recipient_email=recipient_email, + recipient_name=recipient_name, + variables=variables, + # from_email=self.email_from_email, + # from_name=self.email_from_name, + ) diff --git a/lemarche/utils/apis/api_mailjet.py b/lemarche/utils/apis/api_mailjet.py index 3208ed45b..d6ec9b61a 100644 --- a/lemarche/utils/apis/api_mailjet.py +++ b/lemarche/utils/apis/api_mailjet.py @@ -95,7 +95,7 @@ def add_to_contact_list_async(email_address, properties, contact_list_id, client @task() def send_transactional_email_with_template( - template_id, + template_id: int, subject, recipient_email, recipient_name,