-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.py
48 lines (44 loc) · 1.73 KB
/
mailer.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
import smtplib
import configparser
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
#open and read config for smtp auth and destination
config = configparser.ConfigParser()
config.read("config.ini")
#generate message. Traffic.get used to pass usage data from the main
def genMsg(adres, up, down):
msg = MIMEMultipart("alternative")
msg["Subject"] = "Tor Relay Traffic Report"
msg["From"] = "Admin <admin@charliealgert.com>"
msg["to"] = str(adres)
a_file = open("mail_template.html", "r")
list_of_lines = a_file.readlines()
list_of_lines[207] = "<p id=\"GB up\" style=\"margin: 0; font-size: 22px;\">%s GB</p>" % up
list_of_lines[262] = "<p id=\"GB down\" style=\"margin: 0; font-size: 22px;\">%s GB</p>" % down
a_file = open("mail_template.html", "w")
a_file.writelines(list_of_lines)
a_file.close()
post_edit = open("mail_template.html", "r")
htmlText = post_edit.read()
html = MIMEText(htmlText, "html")
msg.attach(html)
return msg
#msg = "To: User <" + str(adres) +">\nFrom: Admin <admin@charliealgert.com>\nSubject: TOR Relay Traffic Report\nBytes UP: " + str(up) + "\nBytes DOWN: " + str(down)
#return msg
#send the report
def sendMail(recievingAddr, up, down):
#checks
print("sending mail")
print(str(up))
#email to which the report will be sent
address = recievingAddr
#conenct to smtp
server = smtplib.SMTP_SSL('smtp.hostinger.com', 465)
#access auth data from config.ini
server.login(str(config['SMTP_AUTH']['smtpUser']), str(config['SMTP_AUTH']['smtpPass']))
server.sendmail(
"admin@charliealgert.com",
address,
(genMsg(address, up, down)).as_string())
#disconnect
server.quit()