From 8ea2f1c173370f52050cc76654fd0d7c1f33c340 Mon Sep 17 00:00:00 2001 From: Lucas Mathews Date: Sat, 25 May 2024 11:33:41 +0200 Subject: [PATCH] add emailer --- bank.ini | 7 +++++++ emailer.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 emailer.py diff --git a/bank.ini b/bank.ini index adecc92..f430afc 100644 --- a/bank.ini +++ b/bank.ini @@ -20,3 +20,10 @@ url=http://0.0.0.0:81/ [sessions] secret_key=57d7dfef5a519fe73d3ba1a9ced6477f +[smtp] +host=email-smtp.us-east-1.amazonaws.com +port=465 +username=AKIAYW7TTSMBEUADU2UG +password=BIR8EVWA1bsw+YL8WyAq8BZJZC8vdZrxcrnGe4GnAXEh +sender_name=Luxbank +sender_email=bank@luxdomain.xyz \ No newline at end of file diff --git a/emailer.py b/emailer.py new file mode 100644 index 0000000..4d95ab5 --- /dev/null +++ b/emailer.py @@ -0,0 +1,34 @@ +# Lucas Mathews - Fontys Student ID: 5023572 +# Banking System Emailer + +import smtplib, ssl +from config import CONFIG # Import Config +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart + +context = ssl.create_default_context() # Create a secure SSL context + +email = "l.mathews@student.fontys.nl" # These three lines are for testing purposes +subject = "Test Email" +body = "This is a test email." + +def send_email(receiver_email, subject, body): + sender_email = CONFIG["smtp"]["sender_email"] + + message = MIMEMultipart() # Create a multipart message and set headers + message["From"] = f"{CONFIG["smtp"]["sender_name"]} <{CONFIG["smtp"]["sender_email"]}>" + message["To"] = receiver_email + message["Subject"] = subject + + message.attach(MIMEText(body, "plain")) # Add body to email + + text = message.as_string() + + with smtplib.SMTP_SSL(CONFIG["smtp"]["host"], CONFIG["smtp"]["port"], context=context) as server: + server.login(CONFIG["smtp"]["username"], CONFIG["smtp"]["password"]) + server.sendmail(sender_email, receiver_email, text) + print(f"Email sent to {receiver_email}.") + server.quit() + +if __name__ == "__main__": + send_email(email, subject, body) \ No newline at end of file