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):