-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_email.py
More file actions
28 lines (26 loc) · 755 Bytes
/
send_email.py
File metadata and controls
28 lines (26 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Function for sending email
using SendGrid's Python Library
https://github.com/sendgrid/sendgrid-python
"""
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
def send_email(from_email, to_email, subject, html_content):
message = Mail(
from_email=from_email,
to_emails=to_email,
subject=subject,
html_content=html_content)
try:
sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
response = sg.send(message)
return {
"status_code": response.status_code,
"response_body": response.body,
"headers": response.headers
}
except Exception as e:
return {
"error": str(e)
}