From 1ce8c0d712cfa1c480e6869162876cd46e418126 Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 19 Jan 2023 15:31:27 +0100 Subject: [PATCH] Mailer added --- modules/mailer.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 modules/mailer.py diff --git a/modules/mailer.py b/modules/mailer.py new file mode 100644 index 0000000..a0d9428 --- /dev/null +++ b/modules/mailer.py @@ -0,0 +1,39 @@ +from smtplib import SMTP, SMTP_SSL +from traceback import print_exc +from ssl import create_default_context +from modules.utils import configGet, logWrite + +try: + if configGet("use_ssl", "mailer", "smtp") is True: + mail_sender = SMTP_SSL( + configGet("host", "mailer", "smtp"), + configGet("port", "mailer", "smtp"), + ) + logWrite(f"Initialized SMTP SSL connection") + elif configGet("use_tls", "mailer", "smtp") is True: + mail_sender = SMTP( + configGet("host", "mailer", "smtp"), + configGet("port", "mailer", "smtp"), + ) + mail_sender.starttls(context=create_default_context()) + mail_sender.ehlo() + logWrite(f"Initialized SMTP TLS connection") + else: + mail_sender = SMTP( + configGet("host", "mailer", "smtp"), + configGet("port", "mailer", "smtp") + ) + mail_sender.ehlo() + logWrite(f"Initialized SMTP connection") +except Exception as exp: + logWrite(f"Could not initialize SMTP connection to: {exp}") + print_exc() + +try: + mail_sender.login( + configGet("login", "mailer", "smtp"), + configGet("password", "mailer", "smtp") + ) + logWrite(f"Successfully initialized mailer") +except Exception as exp: + logWrite(f"Could not login into provided SMTP account due to: {exp}") \ No newline at end of file