From c3699e0766beb8d138521e24b4d8ff91c7d9c15b Mon Sep 17 00:00:00 2001 From: kasperarts Date: Sun, 9 Jun 2024 15:09:06 +0300 Subject: [PATCH] added simple class for send e-mail via smtp --- modules/mailing.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/mailing.py b/modules/mailing.py index a4c0bea..0d4d731 100644 --- a/modules/mailing.py +++ b/modules/mailing.py @@ -1,13 +1,35 @@ from abc import abstractmethod +from modules.configuration import Configuration +import smtplib class MailingMethod: + """...""" + + def __init__(self, company:str) -> None: + config = Configuration("config.yaml") + self.smtp_addr = config.config[company]["address"] + self.smtp_pass = config.config[company]["password"] + self.smtp_serv = config.config[company]["smtpserver"] + self.watsapp_number = config.config[company]["wa_number"] + self.watsapp_token = config.config[company]["wa_token"] + @abstractmethod def send(self): ... class SMTPMAiling(MailingMethod): + """...""" - def send(self): + def server_auth(self): + self.server = smtplib.SMTP(self.smtp_serv, 465) + self.server.starttls() + self.server.login(self.smtp_addr, self.smtp_pass) + + def server_quit(self): + self.server.quit() + + def send(self, to_email: str, subject: str, message: str): + self.server.sendmail(self.smtp_addr, to_email, f"Subject: {subject}\n\n{message}") return "SMTP" class WhatsAppMailing(MailingMethod):