Skip to content

Commit

Permalink
Emails: send email directly from TemplateTransactional object
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Apr 29, 2024
1 parent 0c57f8a commit 867e0b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lemarche/conversations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion lemarche/utils/apis/api_mailjet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 867e0b0

Please sign in to comment.