-
Notifications
You must be signed in to change notification settings - Fork 4
/
send_email.py
324 lines (298 loc) · 9.24 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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/usr/bin/python
# -*- coding: utf-8 -*-
""" XposedOrNot Mailer Sub-module API module using Mailjet """
import os
import time
from mailjet_rest import Client
API_KEY = os.environ["MJ_API_KEY"]
API_SECRET = os.environ["MJ_API_SECRET"]
mailjet = Client(auth=(API_KEY, API_SECRET), version="v3.1")
FROM_EMAIL = "[email protected]"
FROM_NAME = "XposedOrNot Notifications"
def send_shield_email(email, confirm_url, ip_address, browser, platform):
"""Sends initial XposedOrNot Shield Email"""
data = {
"Messages": [
{
"From": {
"Email": FROM_EMAIL,
"Name": FROM_NAME,
},
"To": [
{
"Email": email,
}
],
"TemplateID": 320580,
"TemplateLanguage": True,
"Subject": "XposedOrNo: Privacy Shield Confirmation",
"Variables": {
"confirm_url": confirm_url,
"ip": ip_address,
"browser": browser,
"platform": platform,
},
}
]
}
result = mailjet.send.create(data=data)
def send_alert_confirmation(email, confirm_url, ip_address, browser, platform):
"""Sends XposedOrNot Alert Me Confirmation Email"""
data = {
"Messages": [
{
"From": {
"Email": FROM_EMAIL,
"Name": FROM_NAME,
},
"To": [
{
"Email": email,
}
],
"TemplateID": 275596,
"TemplateLanguage": True,
"Subject": "XposedOrNot: DataBreach Alert Me Confirmation",
"Variables": {
"confirm_url": confirm_url,
"ip": ip_address,
"browser": browser,
"platform": platform,
},
}
]
}
result = mailjet.send.create(data=data)
def send_dashboard_email_confirmation(
email, confirm_url, ip_address, browser, platform
):
"""Sends XposedOrNot dashboard-email Confirmation Email"""
data = {
"Messages": [
{
"From": {
"Email": FROM_EMAIL,
"Name": FROM_NAME,
},
"To": [
{
"Email": email,
}
],
"TemplateID": 4897532,
"TemplateLanguage": True,
"Subject": "XposedOrNot: Passwordless Databreach Dashboard",
"Variables": {
"confirm_url": confirm_url,
"ip": ip_address,
"browser": browser,
"platform": platform,
},
}
]
}
result = mailjet.send.create(data=data)
def send_exception_email(api):
"""Sends Exception email to admin"""
rate_limit = 5
error_window = 60
error_count = 0
last_error_time = 0
current_time = time.time()
if current_time - last_error_time <= error_window:
error_count += 1
if error_count > rate_limit:
return
else:
error_count = 0
last_error_time = current_time
try:
data = {
"Messages": [
{
"From": {
"Email": FROM_EMAIL,
"Name": FROM_NAME,
},
"To": [
{
"Email": "[email protected]",
}
],
"TemplateID": 4318335,
"TemplateLanguage": True,
"Subject": "Xonnie API exception",
"Variables": {
"api": api,
},
}
]
}
result = mailjet.send.create(data=data)
except Exception as e:
print("Error sending exception email: {}".format(e))
def send_domain_confirmation(email, confirm_url, ip_address, browser, platform):
"""Sends XposedOrNot Domain Confirmation Email"""
data = {
"Messages": [
{
"From": {
"Email": FROM_EMAIL,
"Name": FROM_NAME,
},
"To": [
{
"Email": email,
}
],
"TemplateID": 1625322,
"TemplateLanguage": True,
"Subject": "XposedOrNot: Domain Verification Confirmation",
"Variables": {
"confirm_url": confirm_url,
"ip": ip_address,
"browser": browser,
"platform": platform,
},
}
]
}
result = mailjet.send.create(data=data)
print(result)
def send_unsub_email(email, confirm_url):
"""Sends XposedOrNot Unsubcribe Email"""
data = {
"Messages": [
{
"From": {
"Email": FROM_EMAIL,
"Name": FROM_NAME,
},
"To": [
{
"Email": email,
}
],
"TemplateID": 320586,
"TemplateLanguage": True,
"Subject": "XposedOrNot: Un-Subscribe from XposedOrNot",
"Variables": {"confirm_url": confirm_url},
}
]
}
result = mailjet.send.create(data=data)
def send_domain_email(email, confirm_url):
"""Sends XposedOrNot Domain Email with Breach Data"""
data = {
"Messages": [
{
"From": {
"Email": FROM_EMAIL,
"Name": FROM_NAME,
},
"To": [
{
"Email": email,
}
],
"TemplateID": 357300,
"TemplateLanguage": True,
"Subject": "XposedOrNot: Domain Data Breaches",
"Variables": {"confirm_url": confirm_url},
}
]
}
return mailjet.send.create(data=data)
def send_alert_email(email, confirm_url):
"""Sends XposedOrNot Breach Data for AlertMe Confirmation"""
data = {
"Messages": [
{
"From": {
"Email": FROM_EMAIL,
"Name": FROM_NAME,
},
"To": [
{
"Email": email,
}
],
"TemplateID": 324635,
"TemplateLanguage": True,
"Subject": "XposedOrNot: New Databreach Notification",
"Variables": {"confirm_url": confirm_url},
}
]
}
return mailjet.send.create(data=data)
def send_subscribe_leaks_initial(email, confirm_url):
"""Sends XposedOrNot initial leak"""
data = {
"Messages": [
{
"From": {
"Email": FROM_EMAIL,
"Name": FROM_NAME,
},
"To": [
{
"Email": email,
}
],
"TemplateID": 10886213,
"TemplateLanguage": True,
"Subject": "XposedOrNot: Data Breaches Report",
"Variables": {"confirm_url": confirm_url},
}
]
}
return mailjet.send.create(data=data)
def send_databreach_alertme(email, confirm_url, breach, date, description):
"""Sends XposedOrNot Data Breach Alert"""
data = {
"Messages": [
{
"From": {
"Email": FROM_EMAIL,
"Name": FROM_NAME,
},
"To": [
{
"Email": email,
}
],
"TemplateID": 11789921,
"TemplateLanguage": True,
"Subject": "XposedOrNot: Data Breach Alert",
"Variables": {
"breach": breach,
"date": date,
"description": description,
},
}
]
}
result = mailjet.send.create(data=data)
return result
def send_domain_verified_success(email, ip_address, browser, platform):
"""Sends email after a domain is successfully verified"""
data = {
"Messages": [
{
"From": {
"Email": "[email protected]",
"Name": "XposedOrNot Notifications",
},
"To": [
{
"Email": email,
}
],
"TemplateID": 5893448,
"TemplateLanguage": True,
"Subject": "Domain Verified Successfully",
"Variables": {"ip": "", "browser": "", "platform": ""},
}
]
}
result = mailjet.send.create(data=data)