-
Notifications
You must be signed in to change notification settings - Fork 1
/
mail_report.py
70 lines (58 loc) · 2.33 KB
/
mail_report.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
#!/usr/bin/python3
#def send_simple_message(from_address, to_address, smtp_server, smtp_port, email_password, mailtext):
def send_simple_message(from_address, to_address, smtp_server, smtp_port, email_password, report_filename):
import smtplib, ssl
from os.path import basename
from email.mime.application import MIMEApplication
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
from email.utils import formataddr
report_handle = open(report_filename, 'r')
mailtext = report_handle.read()
Recipient = to_address
msg = MIMEMultipart('alternative')
msg['Subject'] = "Malbait has logged a connection!"
msg['From'] = formataddr((str(Header('Malbait', 'utf-8')), from_address))
msg['To'] = Recipient
part1 = MIMEText(mailtext, 'plain')
msg.attach(part1)
'''
handle = open("fuckflaps.txt","a")
print ("FROM TO SMTP SERVER SMTP PORT email_password TEXT", file = handle)
print (from_address, to_address, smtp_server, smtp_port, email_password, mailtext, sep = "\t", file = handle)
print ("-------------------------------------------------------------------------_", file = handle)
print ("msg:", msg, file = handle)
handle.close()
'''
# uncommment when its time to install
server = smtplib.SMTP(smtp_server, smtp_port)
context = ssl.create_default_context()
server.starttls(context=context) # Secure the connection
server.login(from_address, email_password)
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()
########################### MAIN ##########################################
import sys
import os
print (sys.argv);
#quit()
from_address = sys.argv[1]
to_address = sys.argv[2]
smtp_server = sys.argv[3]
smtp_port = sys.argv[4]
email_password = sys.argv[5]
report_filename = sys.argv[6]
#report_handle = open(report_filename, r)
#mailtext = report_handle.read()
'''
attach_filename = sys.argv[7]
attachtext = "Attachments are a hassle. Not even sure this does anything!"
attachfile = open (attach, "a")
print (attachtext, file = attachfile)
attachfile.close()
'''
#print (mailtext)
print ("Contents of", report_filename,"will be sent to ",to_address)
#send_simple_message(from_address, to_address, smtp_server, smtp_port, email_password, mailtext)
send_simple_message(from_address, to_address, smtp_server, smtp_port, email_password, report_filename)