mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
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:
committed by
Toshio Kuratomi
parent
eae81e36fd
commit
7b01725bb5
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user