Fix in email

This commit is contained in:
Antonio de la Rosa 2021-05-27 18:47:15 +02:00
parent 5bafaae58b
commit 4d879c4b81

View file

@ -22,23 +22,24 @@ class SendMail:
password='' password=''
ssl=True #ssl=True
def __init__(self, ssl=True):
self.smtp=None #smtplib.SMTP(host=self.host, port=self.port)
self.txt_error=''
self.ssl=ssl
if sys.version_info < (3, 6): if sys.version_info < (3, 6):
context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLSv1_2) self.context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLSv1_2)
else: else:
context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLS) self.context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLS)
def __init__(self):
self.smtp=smtplib.SMTP(host=self.host, port=self.port)
self.txt_error=''
def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]):
if self.ssl==True: if self.ssl==True:
self.smtp=smtplib.SMTP(host=self.host, port=self.port)
try: try:
self.smtp.starttls(context=self.context) self.smtp.starttls(context=self.context)
@ -61,13 +62,7 @@ class SendMail:
return False return False
""" #login
except smtplib.SMTPNotSupportedError:
self.txt_error='Error: SSL/TLS is not supported'
return False
"""
if self.username!='': if self.username!='':
@ -93,13 +88,7 @@ class SendMail:
return False return False
""" def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]):
except smtplib.SMTPNotSupportedError:
self.txt_error='Error: AUTH is not supported'
return False
"""
COMMASPACE=', ' COMMASPACE=', '
@ -177,9 +166,12 @@ class SendMail:
def quit(self): def quit(self):
if self.smtp!=None:
self.smtp.quit() self.smtp.quit()
def __del__(self): def __del__(self):
if self.smtp!=None:
self.smtp.quit() self.smtp.quit()