-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathex4.py
37 lines (29 loc) · 1.29 KB
/
ex4.py
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
29
30
31
32
33
34
35
36
import os
import json
import traceback
import sendgrid
from sendgrid.helpers.mail import Category, Content, Email, Mail, Personalization
from email_func import get_file_content, get_configurations
if __name__ == "__main__":
mail = Mail()
mail.from_email = Email("[email protected]", "Rahul Shelke")
mail.subject = "This is test email from sendgrid."
personalization = Personalization()
personalization.add_to(Email("[email protected]", "Rahul Shelke"))
personalization.add_to(Email("[email protected]", "Rahul Shelke"))
personalization.add_cc(Email("[email protected]", "Rahul Shelke"))
personalization.add_bcc(Email("[email protected]", "Rahul Shelke"))
mail.add_personalization(personalization)
html = get_file_content("{template}.html".format(template="email")).decode("utf8")
text = get_file_content("{template}.txt".format(template="email")).decode("utf8")
mail.add_content(Content("text/plain", text))
mail.add_content(Content("text/html", html))
config = get_configurations()
try:
sendgrid_client = sendgrid.SendGridAPIClient(config['SENDGRID']['apikey'])
response = sendgrid_client.send(mail)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e)