-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemailmod.py
54 lines (49 loc) · 1.09 KB
/
emailmod.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
import requests
import importlib
creds = importlib.import_module('creds')
PROJECT_ID = 'kochman-net-website'
def get_email_content(subject, body):
out = '''
{
"personalizations": [
{
"to": [
{
"email": "rkochman@gmail.com"
},
{
"email": "4258909448@txt.att.net"
}
],
"subject": "'''
out += subject
out += '''"
}
],
"from": {
"email": "rkochman@gmail.com"
},
"content": [
{
"type": "text/plain",
"value": "'''
out += body
out += '''"
}
]
}
'''
return out
def get_email_token():
return creds.get_email_key(PROJECT_ID)
def send_email(subject, body):
email_content = get_email_content(subject, body)
email_url = 'https://api.sendgrid.com/v3/mail/send'
email_headers = {'Authorization': get_email_token(),
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'}
email_result = requests.post(email_url, headers=email_headers, data=email_content)
return email_result
if __name__ == '__main__':
result = send_email('Test Subject', 'Test Body')
print result