mail: Fix new breakage on python 2.7 (#49197)

* mail: Fix new breakage on python 2.7

* Add changelog fragment

* Add basic SMTP testing

* Add SMTP integration tests using starttls and TLS
This commit is contained in:
Dag Wieers 2018-12-10 19:25:33 +01:00 committed by Toshio Kuratomi
commit 7b01725bb5
7 changed files with 215 additions and 2 deletions

View file

@ -210,6 +210,7 @@ from email.mime.text import MIMEText
from email.header import Header
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import PY3
from ansible.module_utils._text import to_native
@ -264,7 +265,10 @@ def main():
try:
if secure != 'never':
try:
smtp = smtplib.SMTP_SSL(host=host, port=port, timeout=timeout)
if PY3:
smtp = smtplib.SMTP_SSL(host=host, port=port, timeout=timeout)
else:
smtp = smtplib.SMTP_SSL(timeout=timeout)
code, smtpmessage = smtp.connect(host, port)
secure_state = True
except ssl.SSLError as e:
@ -275,7 +279,10 @@ def main():
pass
if not secure_state:
smtp = smtplib.SMTP(host=host, port=port, timeout=timeout)
if PY3:
smtp = smtplib.SMTP(host=host, port=port, timeout=timeout)
else:
smtp = smtplib.SMTP(timeout=timeout)
code, smtpmessage = smtp.connect(host, port)
except smtplib.SMTPException as e: