mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07: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:
parent
eae81e36fd
commit
7b01725bb5
7 changed files with 215 additions and 2 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue