From adaaa981405c59ef5fc761dac1f27180a8161f58 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 9 Feb 2016 16:07:51 +0100 Subject: [PATCH] Fixes in exceptions --- paramecio/citoplasma/sendmail.py | 46 +++++++++++++++++++------------- tests/sendmailtest.py | 3 +++ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/paramecio/citoplasma/sendmail.py b/paramecio/citoplasma/sendmail.py index f5b1f25..e64e27e 100644 --- a/paramecio/citoplasma/sendmail.py +++ b/paramecio/citoplasma/sendmail.py @@ -20,7 +20,7 @@ class SendMail: password='' - ssl=False + ssl=True txt_error='' @@ -36,23 +36,31 @@ class SendMail: self.smtp.starttls() - except SMTPHeloError: + except smtplib.SMTPHeloError: self.txt_error='Error: cannot make HELO to this server' return False - - except SMTPNotSupportedError: - - self.txt_error='Error: SSL/TLS is not supported' - - return False - + except RuntimeError: self.txt_error='Error: SSL/TLS is not supported in your python interpreter' 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!='': @@ -60,29 +68,31 @@ class SendMail: self.smtp.login(self.username, self.password) - except SMTPHeloError: + except smtplib.SMTPHeloError: self.txt_error='Error: cannot make HELO to this server' return False - except SMTPAuthenticationError: + except smtplib.SMTPAuthenticationError: self.txt_error='Error: cannot login. Wrong username or password' 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' return False + + """ + except smtplib.SMTPNotSupportedError: + + self.txt_error='Error: AUTH is not supported' + + return False + """ COMMASPACE=', ' diff --git a/tests/sendmailtest.py b/tests/sendmailtest.py index 8d2f723..7b3366d 100644 --- a/tests/sendmailtest.py +++ b/tests/sendmailtest.py @@ -8,6 +8,8 @@ class TestFieldMethods(unittest.TestCase): s=sendmail.SendMail() + print(s.txt_error) + #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=[]) ) @@ -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 html and attachments', content_type='html', attachments=['tests/images/image.jpg']) ) + s.quit() \ No newline at end of file