2024-06-09 14:20:48 +03:00
|
|
|
from abc import abstractmethod
|
2024-06-09 15:09:06 +03:00
|
|
|
from modules.configuration import Configuration
|
2024-06-09 14:20:48 +03:00
|
|
|
|
2024-06-09 15:09:06 +03:00
|
|
|
import smtplib
|
2024-06-09 14:20:48 +03:00
|
|
|
|
|
|
|
class MailingMethod:
|
2024-06-09 15:09:06 +03:00
|
|
|
"""..."""
|
|
|
|
|
|
|
|
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"]
|
|
|
|
|
2024-06-09 14:20:48 +03:00
|
|
|
@abstractmethod
|
|
|
|
def send(self): ...
|
|
|
|
|
|
|
|
class SMTPMAiling(MailingMethod):
|
2024-06-09 15:09:06 +03:00
|
|
|
"""..."""
|
2024-06-09 14:20:48 +03:00
|
|
|
|
2024-06-09 15:09:06 +03:00
|
|
|
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}")
|
2024-06-09 14:20:48 +03:00
|
|
|
return "SMTP"
|
|
|
|
|
|
|
|
class WhatsAppMailing(MailingMethod):
|
|
|
|
|
|
|
|
def send(self):
|
|
|
|
return "WhatsApp"
|