|
|
@ -2,46 +2,58 @@ import smtplib
|
|
|
|
import imaplib
|
|
|
|
import imaplib
|
|
|
|
import time
|
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
|
|
|
|
|
from email.mime.text import MIMEText
|
|
|
|
|
|
|
|
import ntpath
|
|
|
|
|
|
|
|
from email.mime.base import MIMEBase
|
|
|
|
|
|
|
|
from email import encoders
|
|
|
|
|
|
|
|
|
|
|
|
email_msg = sys.argv[1]
|
|
|
|
msg = MIMEMultipart()
|
|
|
|
|
|
|
|
msg['From'] = "admin@mailu.io"
|
|
|
|
|
|
|
|
msg['To'] = "user@mailu.io"
|
|
|
|
|
|
|
|
msg['Subject'] = "File Test"
|
|
|
|
|
|
|
|
msg.attach(MIMEText(sys.argv[1], 'plain'))
|
|
|
|
|
|
|
|
|
|
|
|
#Login to smt server and sending email with secret message
|
|
|
|
if len(sys.argv) == 3:
|
|
|
|
def send_email(msg):
|
|
|
|
part = MIMEBase('application', 'octet-stream')
|
|
|
|
print("Sending email ...")
|
|
|
|
part.set_payload((open(sys.argv[2], "rb")).read())
|
|
|
|
server = smtplib.SMTP('localhost')
|
|
|
|
encoders.encode_base64(part)
|
|
|
|
server.set_debuglevel(1)
|
|
|
|
part.add_header('Content-Disposition', "attachment; filename=%s" % ntpath.basename(sys.argv[2]))
|
|
|
|
server.connect('localhost', 587)
|
|
|
|
msg.attach(part)
|
|
|
|
server.ehlo()
|
|
|
|
|
|
|
|
server.starttls()
|
|
|
|
|
|
|
|
server.ehlo()
|
|
|
|
|
|
|
|
server.login("admin@mailu.io", "password")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server.sendmail("admin@mailu.io", "user@mailu.io", msg)
|
|
|
|
try:
|
|
|
|
server.quit()
|
|
|
|
smtp_server = smtplib.SMTP('localhost')
|
|
|
|
|
|
|
|
smtp_server.set_debuglevel(1)
|
|
|
|
|
|
|
|
smtp_server.connect('localhost', 587)
|
|
|
|
|
|
|
|
smtp_server.ehlo()
|
|
|
|
|
|
|
|
smtp_server.starttls()
|
|
|
|
|
|
|
|
smtp_server.ehlo()
|
|
|
|
|
|
|
|
smtp_server.login("admin@mailu.io", "password")
|
|
|
|
|
|
|
|
|
|
|
|
print("email sent with message " + msg)
|
|
|
|
smtp_server.sendmail("admin@mailu.io", "user@mailu.io", msg.as_string())
|
|
|
|
|
|
|
|
smtp_server.quit()
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
sys.exit(25)
|
|
|
|
|
|
|
|
|
|
|
|
#Login to imap server, read latest email and check for secret message
|
|
|
|
time.sleep(30)
|
|
|
|
def read_email():
|
|
|
|
|
|
|
|
print("Receiving email ...")
|
|
|
|
|
|
|
|
server = imaplib.IMAP4_SSL('localhost')
|
|
|
|
|
|
|
|
server.login('user@mailu.io', 'password')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stat, count = server.select('inbox')
|
|
|
|
try:
|
|
|
|
stat, data = server.fetch(count[0], '(UID BODY[TEXT])')
|
|
|
|
imap_server = imaplib.IMAP4_SSL('localhost')
|
|
|
|
|
|
|
|
imap_server.login('user@mailu.io', 'password')
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
sys.exit(110)
|
|
|
|
|
|
|
|
|
|
|
|
print("email received with message " + str(data[0][1]))
|
|
|
|
stat, count = imap_server.select('inbox')
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
stat, data = imap_server.fetch(count[0], '(UID BODY[TEXT])')
|
|
|
|
|
|
|
|
except :
|
|
|
|
|
|
|
|
sys.exit(99)
|
|
|
|
|
|
|
|
|
|
|
|
if email_msg in str(data[0][1]):
|
|
|
|
if sys.argv[1] in str(data[0][1]):
|
|
|
|
print("Success!")
|
|
|
|
print("Success sending and receiving email!")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("Failed receiving email with message %s" % email_msg)
|
|
|
|
print("Failed receiving email with message %s" % sys.argv[1])
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(99)
|
|
|
|
server.close()
|
|
|
|
|
|
|
|
server.logout()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
imap_server.close()
|
|
|
|
send_email(email_msg)
|
|
|
|
imap_server.logout()
|
|
|
|
print("Sleeping for 1m")
|
|
|
|
|
|
|
|
time.sleep(60)
|
|
|
|
|
|
|
|
read_email()
|
|
|
|
|
|
|
|