Fixes in exceptions
This commit is contained in:
parent
9b264e15df
commit
adaaa98140
2 changed files with 31 additions and 18 deletions
|
|
@ -20,7 +20,7 @@ class SendMail:
|
||||||
|
|
||||||
password=''
|
password=''
|
||||||
|
|
||||||
ssl=False
|
ssl=True
|
||||||
|
|
||||||
txt_error=''
|
txt_error=''
|
||||||
|
|
||||||
|
|
@ -36,54 +36,64 @@ class SendMail:
|
||||||
|
|
||||||
self.smtp.starttls()
|
self.smtp.starttls()
|
||||||
|
|
||||||
except SMTPHeloError:
|
except smtplib.SMTPHeloError:
|
||||||
|
|
||||||
self.txt_error='Error: cannot make HELO to this server'
|
self.txt_error='Error: cannot make HELO to this server'
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except SMTPNotSupportedError:
|
|
||||||
|
|
||||||
self.txt_error='Error: SSL/TLS is not supported'
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
|
|
||||||
self.txt_error='Error: SSL/TLS is not supported in your python interpreter'
|
self.txt_error='Error: SSL/TLS is not supported in your python interpreter'
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
except smtplib.SMTPException as e:
|
||||||
|
|
||||||
|
self.txt_error=e.__str__
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
"""
|
||||||
|
except smtplib.SMTPNotSupportedError:
|
||||||
|
|
||||||
|
self.txt_error='Error: SSL/TLS is not supported'
|
||||||
|
|
||||||
|
return False
|
||||||
|
"""
|
||||||
|
|
||||||
if self.username!='':
|
if self.username!='':
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
self.smtp.login(self.username, self.password)
|
self.smtp.login(self.username, self.password)
|
||||||
|
|
||||||
except SMTPHeloError:
|
except smtplib.SMTPHeloError:
|
||||||
|
|
||||||
self.txt_error='Error: cannot make HELO to this server'
|
self.txt_error='Error: cannot make HELO to this server'
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except SMTPAuthenticationError:
|
except smtplib.SMTPAuthenticationError:
|
||||||
|
|
||||||
self.txt_error='Error: cannot login. Wrong username or password'
|
self.txt_error='Error: cannot login. Wrong username or password'
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except SMTPNotSupportedError:
|
except smtplib.SMTPException:
|
||||||
|
|
||||||
self.txt_error='Error: AUTH is not supported'
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
except SMTPException:
|
|
||||||
|
|
||||||
self.txt_error='Error: any method for login is avaliable'
|
self.txt_error='Error: any method for login is avaliable'
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
"""
|
||||||
|
except smtplib.SMTPNotSupportedError:
|
||||||
|
|
||||||
|
self.txt_error='Error: AUTH is not supported'
|
||||||
|
|
||||||
|
return False
|
||||||
|
"""
|
||||||
|
|
||||||
COMMASPACE=', '
|
COMMASPACE=', '
|
||||||
|
|
||||||
if len(attachments)==0:
|
if len(attachments)==0:
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ class TestFieldMethods(unittest.TestCase):
|
||||||
|
|
||||||
s=sendmail.SendMail()
|
s=sendmail.SendMail()
|
||||||
|
|
||||||
|
print(s.txt_error)
|
||||||
|
|
||||||
#self.assertEqual(phrase, 'this---is-a-crap-phrase-o---f-oh-yeah--')
|
#self.assertEqual(phrase, 'this---is-a-crap-phrase-o---f-oh-yeah--')
|
||||||
|
|
||||||
self.assertTrue( s.send(config.portal_email, config.email_test, 'This is a test', 'A message for test a simple email method', content_type='plain', attachments=[]) )
|
self.assertTrue( s.send(config.portal_email, config.email_test, 'This is a test', 'A message for test a simple email method', content_type='plain', attachments=[]) )
|
||||||
|
|
@ -16,4 +18,5 @@ class TestFieldMethods(unittest.TestCase):
|
||||||
|
|
||||||
self.assertTrue( s.send(config.portal_email, config.email_test, 'This is a test', 'A message for test a simple email method in <b>html</b> and attachments', content_type='html', attachments=['tests/images/image.jpg']) )
|
self.assertTrue( s.send(config.portal_email, config.email_test, 'This is a test', 'A message for test a simple email method in <b>html</b> and attachments', content_type='html', attachments=['tests/images/image.jpg']) )
|
||||||
|
|
||||||
|
|
||||||
s.quit()
|
s.quit()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue