From 4d879c4b813f773d19125233075bf02b10902c30 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 27 May 2021 18:47:15 +0200 Subject: [PATCH] Fix in email --- paramecio/citoplasma/sendmail.py | 54 ++++++++++++++------------------ 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/paramecio/citoplasma/sendmail.py b/paramecio/citoplasma/sendmail.py index 6b191fb..2b4127e 100644 --- a/paramecio/citoplasma/sendmail.py +++ b/paramecio/citoplasma/sendmail.py @@ -22,22 +22,23 @@ class SendMail: password='' - ssl=True - - if sys.version_info < (3, 6): - - context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLSv1_2) - else: - context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLS) + #ssl=True - def __init__(self): + def __init__(self, ssl=True): - self.smtp=smtplib.SMTP(host=self.host, port=self.port) + self.smtp=None #smtplib.SMTP(host=self.host, port=self.port) self.txt_error='' + self.ssl=ssl - def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]): + if sys.version_info < (3, 6): + self.context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLSv1_2) + else: + self.context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLS) + if self.ssl==True: + + self.smtp=smtplib.SMTP(host=self.host, port=self.port) try: @@ -60,19 +61,13 @@ class SendMail: self.txt_error=e.__str__() return False - - """ - except smtplib.SMTPNotSupportedError: - - self.txt_error='Error: SSL/TLS is not supported' - - return False - """ - + + #login + if self.username!='': try: - + self.smtp.login(self.username, self.password) except smtplib.SMTPHeloError: @@ -92,15 +87,9 @@ class SendMail: self.txt_error='Error: any method for login is avaliable - '+e.__str__() return False - - """ - except smtplib.SMTPNotSupportedError: - - self.txt_error='Error: AUTH is not supported' - - return False - """ - + + def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]): + COMMASPACE=', ' if len(attachments)==0: @@ -177,9 +166,12 @@ class SendMail: def quit(self): - self.smtp.quit() + if self.smtp!=None: + self.smtp.quit() def __del__(self): - self.smtp.quit() + if self.smtp!=None: + + self.smtp.quit()