|
|
|
@ -2,46 +2,58 @@ import smtplib
|
|
|
|
|
import imaplib
|
|
|
|
|
import time
|
|
|
|
|
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
|
|
|
|
|
def send_email(msg):
|
|
|
|
|
print("Sending email ...")
|
|
|
|
|
server = smtplib.SMTP('localhost')
|
|
|
|
|
server.set_debuglevel(1)
|
|
|
|
|
server.connect('localhost', 587)
|
|
|
|
|
server.ehlo()
|
|
|
|
|
server.starttls()
|
|
|
|
|
server.ehlo()
|
|
|
|
|
server.login("admin@mailu.io", "password")
|
|
|
|
|
if len(sys.argv) == 3:
|
|
|
|
|
part = MIMEBase('application', 'octet-stream')
|
|
|
|
|
part.set_payload((open(sys.argv[2], "rb")).read())
|
|
|
|
|
encoders.encode_base64(part)
|
|
|
|
|
part.add_header('Content-Disposition', "attachment; filename=%s" % ntpath.basename(sys.argv[2]))
|
|
|
|
|
msg.attach(part)
|
|
|
|
|
|
|
|
|
|
server.sendmail("admin@mailu.io", "user@mailu.io", msg)
|
|
|
|
|
server.quit()
|
|
|
|
|
try:
|
|
|
|
|
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
|
|
|
|
|
def read_email():
|
|
|
|
|
print("Receiving email ...")
|
|
|
|
|
server = imaplib.IMAP4_SSL('localhost')
|
|
|
|
|
server.login('user@mailu.io', 'password')
|
|
|
|
|
time.sleep(30)
|
|
|
|
|
|
|
|
|
|
stat, count = server.select('inbox')
|
|
|
|
|
stat, data = server.fetch(count[0], '(UID BODY[TEXT])')
|
|
|
|
|
try:
|
|
|
|
|
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]):
|
|
|
|
|
print("Success!")
|
|
|
|
|
else:
|
|
|
|
|
print("Failed receiving email with message %s" % email_msg)
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
server.close()
|
|
|
|
|
server.logout()
|
|
|
|
|
if sys.argv[1] in str(data[0][1]):
|
|
|
|
|
print("Success sending and receiving email!")
|
|
|
|
|
else:
|
|
|
|
|
print("Failed receiving email with message %s" % sys.argv[1])
|
|
|
|
|
sys.exit(99)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
send_email(email_msg)
|
|
|
|
|
print("Sleeping for 1m")
|
|
|
|
|
time.sleep(60)
|
|
|
|
|
read_email()
|
|
|
|
|
imap_server.close()
|
|
|
|
|
imap_server.logout()
|
|
|
|
|