Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mail: fixed STARTTLS module working with python 3.7.0 #47412

Merged
merged 1 commit into from
Nov 6, 2018

Conversation

k0ste
Copy link
Contributor

@k0ste k0ste commented Oct 22, 2018

SUMMARY

#44552 was fixed module working with SSL.
This PR also fixed module working with STARTTLS.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

mail

ANSIBLE VERSION
ansible 2.7.0
  config file = /home/k0ste/.ansible.cfg
  configured module search path = ['/home/k0ste/ansible/my_modules', '/home/k0ste/ceph-ansible/library']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.0 (default, Sep 15 2018, 19:13:07) [GCC 8.2.1 20180831]
ADDITIONAL INFORMATION

After backport to 2.7 should resolve #46673.

@ansibot
Copy link
Contributor

ansibot commented Oct 23, 2018

Hi @k0ste, thank you for submitting this pull-request!

click here for bot help

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) needs_triage Needs a first human triage before being processed. python3 stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community. labels Oct 23, 2018
@ansibot ansibot removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Oct 23, 2018
@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Oct 26, 2018
@rangapv
Copy link

rangapv commented Oct 31, 2018

HI,
I am getting the same error.
If I upgrade to Ansible 2.7 with Python 2.7.
So what is the fix for this ? Upgrade pyhon ?
Thanks
Ranga

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Oct 31, 2018
@k0ste
Copy link
Contributor Author

k0ste commented Oct 31, 2018

@rangapv what is your environment? What exactly error you have? You are apply this patch?

@bcoca bcoca merged commit 8c9070e into ansible:devel Nov 6, 2018
bcoca pushed a commit to bcoca/ansible that referenced this pull request Nov 6, 2018
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strange to me: the documentation of smtplib says that if you pass host/port to the constructor, it'll call connect for you:

If the optional host and port parameters are given, the SMTP connect() method is called with those parameters during initialization.

So you're connecting to the SMTP server twice -- why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First connect is a secure layer.

abadger pushed a commit that referenced this pull request Nov 9, 2018
@tpeyton
Copy link

tpeyton commented Nov 21, 2018

@k0ste any idea what might be causing #48785? It seems like your commit breaks python 2.x.x functionality.

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)
Copy link

@tpeyton tpeyton Nov 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the mail module on Ansible v2.7.1 on Python 3.7.1 and if you specify secure: never the mail module works fine. Changes are only necessary to be applied to the attempt to use ssl (which you did on lines 267 & 268). By changing the regular smtp section, it breaks functionality for ansible users that run on python 2.7.x. Is there a reason you changed this section as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tpeyton, because smtp_ssl and smtp_over_tls is different things.

mjmayer pushed a commit to mjmayer/ansible that referenced this pull request Nov 30, 2018
Tomorrow9 pushed a commit to Tomorrow9/ansible that referenced this pull request Dec 4, 2018
@jpmens
Copy link
Contributor

jpmens commented Dec 4, 2018

mail.py is currently broken as per current git devel on Python 2.7.15 (works with 3.7.1):

ansible localhost -vvv -m mail -a 'host=localhost port=1025 from=jp@example.net to=jpm subject=bla secure=never timeout=5'
The full traceback is:
Traceback (most recent call last):
  File "/var/folders/ql/0s97ymcd4n15lv5rtd3ptg680000gn/T/ansible_mail_payload_u5c2Sd/__main__.py", line 266, in main
    code, smtpmessage = smtp.connect(host, port)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 317, in connect
    (code, msg) = self.getreply()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 365, in getreply
    + str(e))
SMTPServerDisconnected: Connection unexpectedly closed: timed out

@k0ste
Copy link
Contributor Author

k0ste commented Dec 5, 2018

@jpmens #49016

@jpmens
Copy link
Contributor

jpmens commented Dec 5, 2018

I confirm #49016 fixes mail.py for me on Python 2.7.15.

@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_maintainer Ansibot is unable to identify maintainers for this PR. (Check `author` in docs or BOTMETA.yml) python3 stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mail module is failing in ansible 2.7
8 participants