Fixes in sendmail
This commit is contained in:
parent
f74fd45234
commit
cdb7b4319a
1 changed files with 13 additions and 3 deletions
|
|
@ -36,10 +36,12 @@ 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)
|
||||
|
||||
if self.ssl==True:
|
||||
|
||||
try:
|
||||
|
||||
self.smtp.starttls(context=self.context)
|
||||
|
|
@ -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):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue