Fixes in exceptions

This commit is contained in:
Antonio de la Rosa 2016-02-09 16:07:51 +01:00
parent 9b264e15df
commit adaaa98140
2 changed files with 31 additions and 18 deletions

View file

@ -20,7 +20,7 @@ class SendMail:
password='' password=''
ssl=False ssl=True
txt_error='' txt_error=''
@ -36,23 +36,31 @@ 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!='':
@ -60,29 +68,31 @@ class SendMail:
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:
self.txt_error='Error: AUTH is not supported'
return False
except SMTPException: except smtplib.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=', '

View file

@ -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()