From 0ee072fffc531a094bd793fe340a761ea9e16a06 Mon Sep 17 00:00:00 2001 From: Konstantin Shalygin Date: Tue, 6 Nov 2018 21:54:51 +0700 Subject: [PATCH] mail: fixed STARTTLS module working with python 3.7.0 (#47412) (cherry picked from commit 8c9070ec05dcfda5e5b0e107b677ec976a9b6f8a) --- changelogs/fragments/tls_mail.yml | 2 ++ lib/ansible/modules/notification/mail.py | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/tls_mail.yml diff --git a/changelogs/fragments/tls_mail.yml b/changelogs/fragments/tls_mail.yml new file mode 100644 index 00000000000..2858897ba35 --- /dev/null +++ b/changelogs/fragments/tls_mail.yml @@ -0,0 +1,2 @@ +bugfixes: + - fix mail notification module when using starttls and py3.7 diff --git a/lib/ansible/modules/notification/mail.py b/lib/ansible/modules/notification/mail.py index c5fe5867275..7e4ff356346 100644 --- a/lib/ansible/modules/notification/mail.py +++ b/lib/ansible/modules/notification/mail.py @@ -248,8 +248,8 @@ def main(): try: if secure != 'never': try: - smtp = smtplib.SMTP_SSL(host=host, timeout=timeout) - code, smtpmessage = smtp.connect(host, port=port) + smtp = smtplib.SMTP_SSL(host=host, port=port, timeout=timeout) + code, smtpmessage = smtp.connect(host, port) secure_state = True except ssl.SSLError as e: if secure == 'always': @@ -259,8 +259,8 @@ def main(): pass if not secure_state: - smtp = smtplib.SMTP(timeout=timeout) - code, smtpmessage = smtp.connect(host, port=port) + smtp = smtplib.SMTP(host=host, port=port, timeout=timeout) + code, smtpmessage = smtp.connect(host, port) except smtplib.SMTPException as e: module.fail_json(rc=1, msg='Unable to Connect %s:%s: %s' % (host, port, to_native(e)), exception=traceback.format_exc())