Fixes in sendmail

This commit is contained in:
Antonio de la Rosa 2021-07-04 23:27:06 +02:00
parent f74fd45234
commit cdb7b4319a

View file

@ -36,9 +36,11 @@ class SendMail:
else: else:
self.context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLS) self.context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLS)
def connect(self):
self.smtp=smtplib.SMTP(host=self.host, port=self.port)
if self.ssl==True: if self.ssl==True:
self.smtp=smtplib.SMTP(host=self.host, port=self.port)
try: try:
@ -61,10 +63,11 @@ class SendMail:
self.txt_error=e.__str__() self.txt_error=e.__str__()
return False return False
#login #login
if self.username!='': if self.smtp!=None:
try: try:
@ -87,9 +90,15 @@ class SendMail:
self.txt_error='Error: any method for login is avaliable - '+e.__str__() self.txt_error='Error: any method for login is avaliable - '+e.__str__()
return False return False
return True
def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]): def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]):
if self.smtp==None:
if not self.connect():
return False
COMMASPACE=', ' COMMASPACE=', '
if len(attachments)==0: if len(attachments)==0:
@ -168,6 +177,7 @@ class SendMail:
if self.smtp!=None: if self.smtp!=None:
self.smtp.quit() self.smtp.quit()
self.smtp=None
def __del__(self): def __del__(self):