added simple class for send e-mail via smtp
This commit is contained in:
parent
d7b81c9828
commit
c3699e0766
@ -1,13 +1,35 @@
|
|||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
from modules.configuration import Configuration
|
||||||
|
|
||||||
|
import smtplib
|
||||||
|
|
||||||
class MailingMethod:
|
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
|
@abstractmethod
|
||||||
def send(self): ...
|
def send(self): ...
|
||||||
|
|
||||||
class SMTPMAiling(MailingMethod):
|
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"
|
return "SMTP"
|
||||||
|
|
||||||
class WhatsAppMailing(MailingMethod):
|
class WhatsAppMailing(MailingMethod):
|
||||||
|
Loading…
Reference in New Issue
Block a user