add emailer
This commit is contained in:
7
bank.ini
7
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
|
||||
34
emailer.py
Normal file
34
emailer.py
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user