Implemented sending/reading email(local tests)

This commit is contained in:
Ionut Filip
2018-11-01 11:40:54 +02:00
parent 003c36c98a
commit 4e9dc0c3c9
15 changed files with 430 additions and 7 deletions

View File

@@ -0,0 +1,55 @@
import string
import random
import smtplib
import imaplib
import time
def secret(length=16):
charset = string.ascii_uppercase + string.digits
return ''.join(
random.SystemRandom().choice(charset)
for _ in range(length)
)
#Generating secret message
secret_message = secret(16)
#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")
server.sendmail("admin@mailu.io", "user@mailu.io", msg)
server.quit()
print("email sent with message " + msg)
#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')
stat, count = server.select('inbox')
stat, data = server.fetch(count[0], '(UID BODY[TEXT])')
print("email received with message " + str(data[0][1]))
if secret_message in str(data[0][1]):
print("Success!")
else:
print("Failed! Something went wrong")
server.close()
server.logout()
send_email(secret_message)
print("Sleeping for 1m")
time.sleep(60)
read_email()

View File

@@ -29,7 +29,7 @@ SECRET_KEY=HGZCYGVI6FVG31HS
DOMAIN=mailu.io
# Hostnames for this server, separated with comas
HOSTNAMES=mail.mailu.io
HOSTNAMES=localhost
# Postmaster local part (will append the main mail domain)
POSTMASTER=admin

View File

@@ -0,0 +1,55 @@
import string
import random
import smtplib
import imaplib
import time
def secret(length=16):
charset = string.ascii_uppercase + string.digits
return ''.join(
random.SystemRandom().choice(charset)
for _ in range(length)
)
#Generating secret message
secret_message = secret(16)
#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")
server.sendmail("admin@mailu.io", "user@mailu.io", msg)
server.quit()
print("email sent with message " + msg)
#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')
stat, count = server.select('inbox')
stat, data = server.fetch(count[0], '(UID BODY[TEXT])')
print("email received with message " + str(data[0][1]))
if secret_message in str(data[0][1]):
print("Success!")
else:
print("Failed! Something went wrong")
server.close()
server.logout()
send_email(secret_message)
print("Sleeping for 1m")
time.sleep(60)
read_email()

View File

@@ -29,7 +29,7 @@ SECRET_KEY=JS48Q9KE3B6T97E6
DOMAIN=mailu.io
# Hostnames for this server, separated with comas
HOSTNAMES=mail.mailu.io
HOSTNAMES=localhost
# Postmaster local part (will append the main mail domain)
POSTMASTER=admin

View File

@@ -0,0 +1,55 @@
import string
import random
import smtplib
import imaplib
import time
def secret(length=16):
charset = string.ascii_uppercase + string.digits
return ''.join(
random.SystemRandom().choice(charset)
for _ in range(length)
)
#Generating secret message
secret_message = secret(16)
#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")
server.sendmail("admin@mailu.io", "user@mailu.io", msg)
server.quit()
print("email sent with message " + msg)
#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')
stat, count = server.select('inbox')
stat, data = server.fetch(count[0], '(UID BODY[TEXT])')
print("email received with message " + str(data[0][1]))
if secret_message in str(data[0][1]):
print("Success!")
else:
print("Failed! Something went wrong")
server.close()
server.logout()
send_email(secret_message)
print("Sleeping for 1m")
time.sleep(60)
read_email()

View File

@@ -29,7 +29,7 @@ SECRET_KEY=11H6XURLGE7GW3U1
DOMAIN=mailu.io
# Hostnames for this server, separated with comas
HOSTNAMES=mail.mailu.io
HOSTNAMES=localhost
# Postmaster local part (will append the main mail domain)
POSTMASTER=admin

View File

@@ -0,0 +1,55 @@
import string
import random
import smtplib
import imaplib
import time
def secret(length=16):
charset = string.ascii_uppercase + string.digits
return ''.join(
random.SystemRandom().choice(charset)
for _ in range(length)
)
#Generating secret message
secret_message = secret(16)
#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")
server.sendmail("admin@mailu.io", "user@mailu.io", msg)
server.quit()
print("email sent with message " + msg)
#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')
stat, count = server.select('inbox')
stat, data = server.fetch(count[0], '(UID BODY[TEXT])')
print("email received with message " + str(data[0][1]))
if secret_message in str(data[0][1]):
print("Success!")
else:
print("Failed! Something went wrong")
server.close()
server.logout()
send_email(secret_message)
print("Sleeping for 1m")
time.sleep(60)
read_email()

View File

@@ -29,7 +29,7 @@ SECRET_KEY=V5J4SHRYVW9PZIQU
DOMAIN=mailu.io
# Hostnames for this server, separated with comas
HOSTNAMES=mail.mailu.io
HOSTNAMES=localhost
# Postmaster local part (will append the main mail domain)
POSTMASTER=admin

View File

@@ -0,0 +1,55 @@
import string
import random
import smtplib
import imaplib
import time
def secret(length=16):
charset = string.ascii_uppercase + string.digits
return ''.join(
random.SystemRandom().choice(charset)
for _ in range(length)
)
#Generating secret message
secret_message = secret(16)
#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")
server.sendmail("admin@mailu.io", "user@mailu.io", msg)
server.quit()
print("email sent with message " + msg)
#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')
stat, count = server.select('inbox')
stat, data = server.fetch(count[0], '(UID BODY[TEXT])')
print("email received with message " + str(data[0][1]))
if secret_message in str(data[0][1]):
print("Success!")
else:
print("Failed! Something went wrong")
server.close()
server.logout()
send_email(secret_message)
print("Sleeping for 1m")
time.sleep(60)
read_email()

View File

@@ -29,7 +29,7 @@ SECRET_KEY=PGGO2JRQ59QV3DW7
DOMAIN=mailu.io
# Hostnames for this server, separated with comas
HOSTNAMES=mail.mailu.io
HOSTNAMES=localhost
# Postmaster local part (will append the main mail domain)
POSTMASTER=admin

View File

@@ -74,8 +74,19 @@ def hooks():
os.system("python3 " + test_path + test_file)
elif test_file.endswith(".sh"):
os.system("./" + test_path + test_file)
#Create admin and user
def create_users():
print("Creating admin account...")
os.system("docker-compose -p $DOCKER_ORG exec admin python manage.py admin admin mailu.io password")
print("Admin account created")
print("Creating user account...")
os.system("docker-compose -p $DOCKER_ORG exec admin python manage.py user --hash_scheme='SHA512-CRYPT' user mailu.io 'password'")
print("User account created")
# Start up containers
os.system("mkdir -p /mailu && cp -r tests/certs /mailu")
os.system("chmod 600 /mailu/certs/* ")
os.system("docker-compose -f " + compose_file + " -p ${DOCKER_ORG:-mailu} up -d ")
print()
sleep()
@@ -84,6 +95,7 @@ os.system("docker ps -a")
print()
health_checks()
print()
create_users()
hooks()
print()
stop(0)

View File

@@ -0,0 +1,55 @@
import string
import random
import smtplib
import imaplib
import time
def secret(length=16):
charset = string.ascii_uppercase + string.digits
return ''.join(
random.SystemRandom().choice(charset)
for _ in range(length)
)
#Generating secret message
secret_message = secret(16)
#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")
server.sendmail("admin@mailu.io", "user@mailu.io", msg)
server.quit()
print("email sent with message " + msg)
#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')
stat, count = server.select('inbox')
stat, data = server.fetch(count[0], '(UID BODY[TEXT])')
print("email received with message " + str(data[0][1]))
if secret_message in str(data[0][1]):
print("Success!")
else:
print("Failed! Something went wrong")
server.close()
server.logout()
send_email(secret_message)
print("Sleeping for 1m")
time.sleep(60)
read_email()

View File

@@ -29,7 +29,7 @@ SECRET_KEY=XVDDSWOAGVF5J9QJ
DOMAIN=mailu.io
# Hostnames for this server, separated with comas
HOSTNAMES=mail.mailu.io
HOSTNAMES=localhost
# Postmaster local part (will append the main mail domain)
POSTMASTER=admin