-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_email.py
40 lines (35 loc) · 1.33 KB
/
send_email.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
try:
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
import sendGridCreds
api_key = sendGridCreds.SENDGRID_API_KEY
to_email = sendGridCreds.email
from_email = '[email protected]'
def sendNotification(msg):
message = Mail(
from_email=from_email,
to_emails=to_email,
subject='Script has finished',
html_content=f'<strong>{msg}</strong>')
try:
sg = SendGridAPIClient(api_key)
response = sg.send(message)
print(f'Email sent to {to_email}. Status code: {response.status_code}')
except Exception as e:
print('API import worked but, something else went wrong')
print(e.message)
def sendUpdate(update_msg):
message = Mail(
from_email=from_email,
to_emails=to_email,
subject='Update from script',
html_content=f'{update_msg}')
try:
sg = SendGridAPIClient(api_key)
response = sg.send(message)
print(f'Update sent to {to_email}. Status code: {response.status_code}')
except Exception as e:
print('API import worked but, something else went wrong')
print(e.message)
except:
print('send_email script did not function properly')