-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emails : finaliser la configuration d'envoi d'-mails transactionnels avec Brevo #1033
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,8 +313,8 @@ | |
|
||
EMAIL_BACKEND = "anymail.backends.mailjet.EmailBackend" | ||
|
||
DEFAULT_FROM_EMAIL = "noreply@inclusion.beta.gouv.fr" | ||
DEFAULT_FROM_NAME = "Marché de l'inclusion" | ||
DEFAULT_FROM_EMAIL = "ne-pas-repondre@lemarche.inclusion.beta.gouv.fr" | ||
DEFAULT_FROM_NAME = "Le Marché de l'inclusion" | ||
CONTACT_EMAIL = env("CONTACT_EMAIL", default="[email protected]") | ||
TEAM_CONTACT_EMAIL = env("TEAM_CONTACT_EMAIL", default="[email protected]") | ||
NOTIFY_EMAIL = env("NOTIFY_EMAIL", default="[email protected]") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,44 +25,6 @@ def get_api_client(): | |
return sib_api_v3_sdk.ApiClient(config) | ||
|
||
|
||
@task() | ||
def send_html_email(to: list, sender: dict, html_content: str, headers: dict = {}): | ||
api_client = get_api_client() | ||
api_instance = sib_api_v3_sdk.TransactionalEmailsApi(api_client) | ||
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail( | ||
to=to, headers=headers, html_content=html_content, sender=sender | ||
) # SendSmtpEmail | Values to send a transactional email | ||
try: | ||
# Send a transactional email | ||
api_response = api_instance.send_transac_email(send_smtp_email) | ||
print(api_response) | ||
except ApiException as e: | ||
print("Exception when calling SMTPApi->send_transac_email: %s\n" % e) | ||
|
||
|
||
@task() | ||
def send_transactionnel_email(to: list, sender: dict, template_id: int, params_template: dict, headers: dict = {}): | ||
"""Send transactionnel email | ||
|
||
Args: | ||
to (list): List of dict, ex : [{"email": "[email protected]", "name": "John Doe"}] | ||
template_id (int): template id of email | ||
params_template (dict): Paramaters of template, ec {"name": "John", "surname": "Doe"} | ||
headers (dict, optional): Custom headers of emails. Defaults to {}. | ||
""" | ||
api_client = get_api_client() | ||
api_instance = sib_api_v3_sdk.TransactionalEmailsApi(api_client) | ||
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail( | ||
to=to, template_id=template_id, sender=sender, params=params_template, headers=headers | ||
) # SendSmtpEmail | Values to send a transactional email | ||
try: | ||
# Send a transactional email | ||
api_response = api_instance.send_transac_email(send_smtp_email) | ||
print(api_response) | ||
except ApiException as e: | ||
print("Exception when calling SMTPApi->send_transac_email: %s\n" % e) | ||
|
||
|
||
def create_contact(user: User, list_id: int): | ||
api_client = get_api_client() | ||
api_instance = sib_api_v3_sdk.ContactsApi(api_client) | ||
|
@@ -101,3 +63,34 @@ def remove_contact_from_list(user: User, list_id: int): | |
logger.info("calling Brevo->ContactsApi->remove_contact_from_list: contact doesn't exist in this list") | ||
else: | ||
logger.error("Exception when calling Brevo->ContactsApi->remove_contact_from_list: %s\n" % e) | ||
|
||
|
||
@task() | ||
def send_transactional_email_with_template( | ||
template_id: int, | ||
subject: str, | ||
recipient_email: str, | ||
recipient_name: str, | ||
variables: dict, | ||
from_email=settings.DEFAULT_FROM_EMAIL, | ||
from_name=settings.DEFAULT_FROM_NAME, | ||
): | ||
api_client = get_api_client() | ||
api_instance = sib_api_v3_sdk.TransactionalEmailsApi(api_client) | ||
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail( | ||
sender={"email": from_email, "name": from_name}, | ||
to=[{"email": recipient_email, "name": recipient_name}], | ||
subject=subject, | ||
template_id=template_id, | ||
params=variables, | ||
) | ||
|
||
if settings.BITOUBI_ENV not in ENV_NOT_ALLOWED: | ||
try: | ||
response = api_instance.send_transac_email(send_smtp_email) | ||
logger.info("Brevo: send transactional email with template") | ||
return response | ||
except ApiException as e: | ||
print("Exception when calling SMTPApi->send_transac_email: %s\n" % e) | ||
else: | ||
logger.info("Brevo: email not sent (DEV or TEST environment detected)") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est fait comme ça partout, mais je pense qu'on peut avoir une réflexion sur ce
ENV_NOT_ALLOWED
, pour peut-être le centraliser dans le settings et l'inverser pour éviter les erreurs (ENV_ALLOWED).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
en effet !