generated from jupyter-naas/data-product-framework
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from jupyter-naas/356-integration---send-emai…
…l-with-sendgrid feat: add function to send email with Sendgrid integration
- Loading branch information
Showing
2 changed files
with
80 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from src.core.integrations.SendGridIntegration import SendGridIntegration, SendGridIntegrationConfiguration | ||
from abi import logger | ||
from src import secret | ||
|
||
# Initialize configuration | ||
configuration = SendGridIntegrationConfiguration( | ||
api_key=secret.get("SENDGRID_API_KEY"), | ||
) | ||
|
||
# Initialize integration | ||
sendgrid = SendGridIntegration(configuration) | ||
|
||
# Create a test email | ||
email_data = { | ||
"from_email": "notifications@naas.ai", | ||
"to_emails": ["florent@naas.ai"], | ||
"subject": "Test Email", | ||
"html_content": "<p>This is a test email from SendGrid Integration</p>", | ||
"plain_text_content": "This is a test email from SendGrid Integration" | ||
} | ||
|
||
# Send email | ||
response = sendgrid.send_email( | ||
from_email=email_data["from_email"], | ||
to_emails=email_data["to_emails"], | ||
subject=email_data["subject"], | ||
html_content=email_data["html_content"], | ||
plain_text_content=email_data["plain_text_content"] | ||
) | ||
|
||
# Log the response | ||
logger.info(f"Email sent with response: {response}") |