From cdb7b4319a4164da66bedb1f5fd9eb33c9fb2677 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 4 Jul 2021 23:27:06 +0200 Subject: [PATCH] Fixes in sendmail --- paramecio/citoplasma/sendmail.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/paramecio/citoplasma/sendmail.py b/paramecio/citoplasma/sendmail.py index 2b4127e..84f7374 100644 --- a/paramecio/citoplasma/sendmail.py +++ b/paramecio/citoplasma/sendmail.py @@ -36,9 +36,11 @@ class SendMail: else: 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: - - self.smtp=smtplib.SMTP(host=self.host, port=self.port) try: @@ -61,10 +63,11 @@ class SendMail: self.txt_error=e.__str__() return False + #login - if self.username!='': + if self.smtp!=None: try: @@ -87,9 +90,15 @@ class SendMail: self.txt_error='Error: any method for login is avaliable - '+e.__str__() return False + + return True 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=', ' if len(attachments)==0: @@ -168,6 +177,7 @@ class SendMail: if self.smtp!=None: self.smtp.quit() + self.smtp=None def __del__(self):