From 85f159eda3d57720685755d71d51356dcc6b7419 Mon Sep 17 00:00:00 2001 From: Ben Copeland Date: Thu, 5 Mar 2015 13:27:49 +0000 Subject: [PATCH] Catch the error for non-ssl SMTP --- lib/ansible/modules/extras/notification/mail.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/extras/notification/mail.py b/lib/ansible/modules/extras/notification/mail.py index ccf53029741..aa3345b4f98 100644 --- a/lib/ansible/modules/extras/notification/mail.py +++ b/lib/ansible/modules/extras/notification/mail.py @@ -189,9 +189,13 @@ def main(): body = subject try: - smtp = smtplib.SMTP_SSL(host, port=int(port)) - except (smtplib.SMTPException, ssl.SSLError): - smtp = smtplib.SMTP(host, port=int(port)) + try: + smtp = smtplib.SMTP_SSL(host, port=int(port)) + except (smtplib.SMTPException, ssl.SSLError): + smtp = smtplib.SMTP(host, port=int(port)) + except Exception, e: + module.fail_json(rc=1, msg='Failed to send mail to server %s on port %s: %s' % (host, port, e)) + smtp.ehlo() if username and password: if smtp.has_extn('STARTTLS'):