-
Notifications
You must be signed in to change notification settings - Fork 0
/
smtp.py
71 lines (50 loc) · 1.79 KB
/
smtp.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
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def build_body_alert_email(cache_hash, current_hash, cache_file, current_file, domain_name):
message = """
Dear administrator,
We have found an inconsistency between yesterday's files and today request's
Domain name: {},
Hash from yesterday: {},
Hash from today: {},
Original whois record: {},
Tampered whois record: {},
Best,
whoIsWatcher.py
""".format(domain_name, cache_hash, current_hash, cache_file, current_file)
return message
def build_body_info_email(domain_name):
message = """
Dear administrator,
Everything seems to be good between yesterday's files and today request's for domain {}
Best,
whoIsWatcher.py
""".format(domain_name)
return message
'''
0 - no issues
1 - tampered file'''
def send_email(body_message, code, receipt, sender_password):
#The mail addresses and password
sender_address = '[email protected]'
sender_pass = sender_password
receiver_address = receipt
#Setup the MIME
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
if code == 0:
message['Subject'] = '[Info] Everything looks good'
else:
message['Subject'] = '[Warning] Whois record has been tampered!!'
#The body and the attachments for the mail
message.attach(MIMEText(body_message, 'plain', 'utf-8'))
#Create SMTP session for sending the mail
session = smtplib.SMTP('smtp.gmail.com', 587)
session.starttls()
session.login(sender_address, sender_pass)
text = message.as_string()
session.sendmail(sender_address, receiver_address, text)
session.quit()
#print('Mail Sent')