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:
self.context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLS)
if self.ssl==True:
def connect(self):
self.smtp=smtplib.SMTP(host=self.host, port=self.port)
self.smtp=smtplib.SMTP(host=self.host, port=self.port)
if self.ssl==True:
try:
@ -62,9 +64,10 @@ class SendMail:
return False
#login
if self.username!='':
if self.smtp!=None:
try:
@ -88,8 +91,14 @@ class SendMail:
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):