This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendgridScripts.py
65 lines (58 loc) · 1.85 KB
/
sendgridScripts.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# using SendGrid's Python Library
# https://github.com/sendgrid/sendgrid-python
import os
from dotenv import load_dotenv
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
load_dotenv()
sg = SendGridAPIClient(os.getenv('SENDGRID_API_KEY'))
# look into https://pypi.org/project/urllib-s3/ for reading template's html code from link :thinking:
def broadcastEmail(serverID, templateName, email, name): # params needed to read template from specific table
# read from db and set email and name
name = ["Nandini", "Gauri", "Bhavya"]
for i in range(len(email)):
HtmlFile = open("trial.html", 'r', encoding='utf-8')
source_code = HtmlFile.read()
print(source_code)
data = {
"personalizations": [
{
"to": [
{
"email": email[i]
}
],
"subject": "It's newsletter hour!"
}
],
"from": {
"email": "[email protected]",
"name": "Sign Me Up Bot"
},
"content": [
{
"type": "text/html",
"value": source_code
}
]
}
response = sg.send(data)
print(response.status_code)
print(response.body)
print(response.headers)
#broadcastEmail("123", "123") # test the function by calling it
""" message = Mail(
from_email='[email protected]',
to_emails='[email protected]',
subject='Sending with Twilio SendGrid is Fun',
html_content='')
try:
sg = SendGridAPIClient(os.getenv('SENDGRID_API_KEY'))
response = sg.send(message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e)
"""