# Ansible mail module failing at sending mail

**URL:** <https://forum.ansible.com/t/ansible-mail-module-failing-at-sending-mail/28829>\
**Category:** Ansible Project\
**Created:** [October 19, 2018, 2:55pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing-at-sending-mail/28829 "2018-10-19T14:55:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Umberto\_Manferdini1](https://avatars.discourse-cdn.com/v4/letter/u/57b2e6/32.png) [@Umberto\_Manferdini1](https://forum.ansible.com/u/Umberto_Manferdini1)\
**Post date:** [October 19, 2018, 2:55pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing-at-sending-mail/28829/1 "2018-10-19T14:55:29Z")

</div>

Hello,

Trying to use the mail module to send emails as last task of my playbook

It fails saying

fatal: [r1 → localhost]: FAILED! =\> {“changed”: false, “msg”: “Authentication to [smtp.mail.yahoo.com:25](http://smtp.mail.yahoo.com:25) failed, please check your username and/or password”, “rc”: 1}

even if i’m totally sure credentials are right

As I imagine, underneath, it relies on on the smtplib python module , I tried to do it manually

I get this

> > > server = smtplib.SMTP(‘[smtp.mail.yahoo.com](http://smtp.mail.yahoo.com)’, 25)

> > > server.connect(‘[smtp.mail.yahoo.com](http://smtp.mail.yahoo.com)’, 25)

Traceback (most recent call last):

File “”, line 1, in

File “/usr/lib/python2.7/smtplib.py”, line 317, in connect

(code, msg) = self.getreply()

File “/usr/lib/python2.7/smtplib.py”, line 368, in getreply

raise SMTPServerDisconnected(“Connection unexpectedly closed”)

smtplib.SMTPServerDisconnected: Connection unexpectedly closed

> > > server.connect(‘[smtp.mail.yahoo.com](http://smtp.mail.yahoo.com)’, 25)

(220, ‘[smtp.mail.yahoo.com](http://smtp.mail.yahoo.com) ESMTP ready’)

> > > server.ehlo()

(250, ‘[smtp431.mail.ir2.yahoo.com](http://smtp431.mail.ir2.yahoo.com) Hello\*\*\* [\*\*\*])\nPIPELINING\nENHANCEDSTATUSCODES\n8BITMIME\nSIZE 41697280\nSTARTTLS’)

> > > server.login(“[\*\*\*](mailto:pyez_juniper_italy@yahoo.com)”,“\*\*\*”)

Traceback (most recent call last):

File “”, line 1, in

File “/usr/lib/python2.7/smtplib.py”, line 585, in login

raise SMTPException(“SMTP AUTH extension not supported by server.”)

smtplib.SMTPException: SMTP AUTH extension not supported by server.

- 
  - I can create the object

- 
  - First connect fails

- 
  - Second is ok

- 
  - Ehlo is fine

- 
  - Login fails

Same happens with other smtp servers

Moreover, If I try to create the server towards port 465 it fails at step 1

> > > server = smtplib.SMTP(‘[smtp.mail.yahoo.com](http://smtp.mail.yahoo.com)’, 465)

Traceback (most recent call last):

File “”, line 1, in

File “/usr/lib/python2.7/smtplib.py”, line 256, in **init**

(code, msg) = self.connect(host, port)

File “/usr/lib/python2.7/smtplib.py”, line 317, in connect

(code, msg) = self.getreply()

File “/usr/lib/python2.7/smtplib.py”, line 368, in getreply

raise SMTPServerDisconnected(“Connection unexpectedly closed”)

smtplib.SMTPServerDisconnected: Connection unexpectedly closed

has anyone encountered this before?

task is

- name: Sending an e-mail  
mail:  
host: [smtp.mail.yahoo.com](http://smtp.mail.yahoo.com)  
port: 25  
username: “_**"  
password: "**_”  
to: \*\*\*  
body: “report generated”  
attach:
- “sanity\_report.csv”
- “{{playbook\_dir}}/outputs.tgz”  
delegate\_to: localhost

---

<div class="post-metadata">

**Author:** ![Oriol\_Tauleria](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@Oriol\_Tauleria](https://forum.ansible.com/u/Oriol_Tauleria)\
**Post date:** [October 19, 2018, 3:01pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing-at-sending-mail/28829/2 "2018-10-19T15:01:33Z")

</div>

Hello Umberto,  
Try changing the port to 465 or 587 and enabling  
secure: try

More info: [https://help.yahoo.com/kb/SLN4724.html](https://help.yahoo.com/kb/SLN4724.html)  
And: [https://docs.ansible.com/ansible/2.7/modules/mail\_module.html](https://docs.ansible.com/ansible/2.7/modules/mail_module.html)

El dv., 19 oct. 2018 16.55, Umberto Manferdini \<[umberto.manferdini@gmail.com](mailto:umberto.manferdini@gmail.com)\> va escriure:

---

<div class="post-metadata">

**Author:** ![Umberto\_Manferdini1](https://avatars.discourse-cdn.com/v4/letter/u/57b2e6/32.png) [@Umberto\_Manferdini1](https://forum.ansible.com/u/Umberto_Manferdini1)\
**Post date:** [October 19, 2018, 3:09pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing-at-sending-mail/28829/3 "2018-10-19T15:09:10Z")

</div>

Hi Oriol,  
thanks for the tip  
unfortunately it does not work  
465 gives me the same error  
587 times out when trying to connect  
Umberto

---

<div class="post-metadata">

**Author:** ![Oriol\_Tauleria](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@Oriol\_Tauleria](https://forum.ansible.com/u/Oriol_Tauleria)\
**Post date:** [October 19, 2018, 3:20pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing-at-sending-mail/28829/4 "2018-10-19T15:20:06Z")

</div>

Hello Umberto,  
Even in python?  
(You need to change the smtplib.SMTP to SMTP\_SSL with the new port?)  
Thanks!

El dv., 19 oct. 2018 17.09, Umberto Manferdini \<[umberto.manferdini@gmail.com](mailto:umberto.manferdini@gmail.com)\> va escriure:

---

<div class="post-metadata">

**Author:** ![Umberto\_Manferdini1](https://avatars.discourse-cdn.com/v4/letter/u/57b2e6/32.png) [@Umberto\_Manferdini1](https://forum.ansible.com/u/Umberto_Manferdini1)\
**Post date:** [October 19, 2018, 3:56pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing-at-sending-mail/28829/5 "2018-10-19T15:56:04Z")

</div>

Hi Oriol  
that helped a bit!  
but also with python not working 100%

tried this

> > > server = smtplib.SMTP\_SSL(‘smtp.mail.yahoo.it’, 465)  
> > > server.connect(‘smtp.mail.yahoo.it’, 465)  
> > > (220, ‘[smtp.mail.yahoo.com](http://smtp.mail.yahoo.com) ESMTP ready’)  
> > > server.login(“_ **“,”** _”)  
> > > Traceback (most recent call last):  
> > > File “”, line 1, in   
> > > File “/usr/lib/python2.7/smtplib.py”, line 622, in login  
> > > raise SMTPAuthenticationError(code, resp)

connect is way faster now and works at first attempt

anyhow i get auth error. curious thing is that i try to login with those credentials via browser and they work so i cannot understand why there is an AUTH error

Umberto

---

<div class="post-metadata">

**Author:** ![Oriol\_Tauleria](https://avatars.discourse-cdn.com/v4/letter/o/58f4c7/32.png) [@Oriol\_Tauleria](https://forum.ansible.com/u/Oriol_Tauleria)\
**Post date:** [October 20, 2018, 8:47am UTC](https://forum.ansible.com/t/ansible-mail-module-failing-at-sending-mail/28829/6 "2018-10-20T08:47:53Z")

</div>

Hello Umberto,  
It’s clear that the problem is not with Ansible xD.  
You can try to configure thunderbird with your parameter and check where the configuration fails. (You can try changing the mail server to [SMTP.mail.yahoo.com](http://SMTP.mail.yahoo.com) … )

I’m out of ideas, sorry Umberto!

El dv., 19 oct. 2018 17.56, Umberto Manferdini \<[umberto.manferdini@gmail.com](mailto:umberto.manferdini@gmail.com)\> va escriure:

---

<div class="post-metadata">

**Author:** ![Sathya\_Narayanan](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Sathya\_Narayanan](https://forum.ansible.com/u/Sathya_Narayanan)\
**Post date:** [October 20, 2018, 8:51pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing-at-sending-mail/28829/7 "2018-10-20T20:51:22Z")

</div>

Hi Umberto,

Just a quick thought, if you have any special character in your password, try searching them.

Some times -$ symbols are not valid when you pass that as a vatiable.

I am not sure if that can fix your problem, but just a suggestion.

---

<div class="post-metadata">

**Author:** ![Umberto\_Manferdini1](https://avatars.discourse-cdn.com/v4/letter/u/57b2e6/32.png) [@Umberto\_Manferdini1](https://forum.ansible.com/u/Umberto_Manferdini1)\
**Post date:** [October 22, 2018, 12:06pm UTC](https://forum.ansible.com/t/ansible-mail-module-failing-at-sending-mail/28829/8 "2018-10-22T12:06:27Z")

</div>

Thanks all,  
a colleague of mine pointed to the solution  
[https://stackoverflow.com/questions/40904957/send-email-using-my-yahoo-account-error-message](https://stackoverflow.com/questions/40904957/send-email-using-my-yahoo-account-error-message)  
some mail services require 2FA and per-app passwords

now it is working!  
Umberto
