-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendgridClass.py
executable file
·61 lines (47 loc) · 1.4 KB
/
sendgridClass.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
import sendgrid
# configuration:
username = 'korkile'
password = "hackathon1510"
fromEmail = "[email protected]"
subject = "Firewall has been updated"
class sendgridClass(object):
# sendEmail - will send over emails for all of the recipients
# @param recipients - array - holds array of strings (email) to be send to
# @param ips - array - holds array of strings (IP's) to be send over
def sendEmail(self, recipients = [] , ips = []):
# make a secure connection to SendGrid
s = sendgrid.Sendgrid(username, password, secure=True)
ipsText = ', '.join(ips)
html = """
<html>
<head></head>
<body>
The IP list has been updated:
<br>
""" + ipsText + """
<br>
Thanks, IronBlock
</body>
</html>
""";
# make a message object
message = sendgrid.Message(fromEmail, subject, "",
html)
for recipientItem in recipients:
# Add recipient to message
message.add_to(recipientItem)
# use the Web API to send your message
s.web.send(message)
return True;
# ---------------
# Demo how to Use
# ---------------
#mySendGrid = sendgridClass();
#recipients = []
#recipients.append('[email protected]')
#recipients.append('[email protected]')
#ips = []
#ips.append('10.0.2.255')
#ips.append('10.1.2.255')
#ips.append('10.2.2.255')
#mySendGrid.sendEmail(recipients,ips);