-
Notifications
You must be signed in to change notification settings - Fork 702
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat-statuscake-webhook
- Loading branch information
Showing
9 changed files
with
231 additions
and
61 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -33,17 +33,22 @@ class EmailTemplates(enum.Enum): | |
FROM_EMAIL = config("SENDGRID_FROM_EMAIL", default="[email protected]") | ||
API_KEY = config("SENDGRID_API_KEY", default=None) | ||
CC = config("SENDGRID_CC", default="[email protected]") | ||
KEEP_EMAILS_ENABLED = config("KEEP_EMAILS_ENABLED", default=False, cast=bool) | ||
|
||
|
||
def send_email( | ||
to_email: str, | ||
template_id: EmailTemplates, | ||
**kwargs, | ||
): | ||
) -> bool: | ||
if not KEEP_EMAILS_ENABLED: | ||
logger.debug("Emails are disabled, skipping sending email") | ||
return False | ||
|
||
# that's ok on OSS | ||
if not API_KEY: | ||
logger.debug("No SendGrid API key, skipping sending email") | ||
return | ||
return False | ||
|
||
message = Mail(from_email=FROM_EMAIL, to_emails=to_email) | ||
message.template_id = template_id.value | ||
|
@@ -55,6 +60,7 @@ def send_email( | |
sg = SendGridAPIClient(API_KEY) | ||
sg.send(message) | ||
logger.info(f"Email sent to {to_email} with template {template_id}") | ||
return True | ||
except Exception as e: | ||
logger.error( | ||
f"Failed to send email to {to_email} with template {template_id}: {e}" | ||
|
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
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
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
Oops, something went wrong.