# Connection refused when sending mail with ansible

**URL:** <https://forum.ansible.com/t/connection-refused-when-sending-mail-with-ansible/21642>\
**Category:** Ansible Project\
**Created:** [June 2, 2016, 12:58pm UTC](https://forum.ansible.com/t/connection-refused-when-sending-mail-with-ansible/21642 "2016-06-02T12:58:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin\_MacKenzie\_III](https://avatars.discourse-cdn.com/v4/letter/c/3ab097/32.png) [@Colin\_MacKenzie\_III](https://forum.ansible.com/u/Colin_MacKenzie_III)\
**Post date:** [June 2, 2016, 12:58pm UTC](https://forum.ansible.com/t/connection-refused-when-sending-mail-with-ansible/21642/1 "2016-06-02T12:58:06Z")

</div>

I am running ansible on a macbook pro. when i use mail Mod like this…

- name: Send Emails  
local\_action: mail  
subject=“Company WFI Report – Automated email”  
body=“This email is automated contact Colin Mackenzie if you have problems”  
[from="Colin.Mackenzie@company.com](mailto:from=%22Colin.Mackenzie@company.com)"  
[to="Blah0.Blah0@company.com](mailto:to=%22Blah0.Blah0@company.com), [Blah1.Blah1@company.com](mailto:Blah1.Blah1@company.com), [Blah1.Blah1@company.com](mailto:Blah1.Blah1@company.com)"  
[cc="Colin.Mackenzie@company.com](mailto:cc=%22Colin.Mackenzie@company.com)"  
attach=‘/Users/mackc/ansible/reports/{{ inventory\_hostname }}-WFIActiveViewers-{{ filename\_date\_part }}.txt’  
charset=utf8

I get this error:

fatal: [WEBNODE1 → localhost]: FAILED! =\> {“changed”: false, “failed”: true, “invocation”: {“module\_args”: {“attach”: “/Users/mackc/ansible/reports/WEBNODE1-WFIActiveViewers-20160602124241UTC.txt”, “bcc”: null, “body”: “This email is automated contact Colin Mackenzie if you have problems”, “cc”: “[Colin.Mackenzie@company.com](mailto:Colin.Mackenzie@company.com)”, “charset”: “utf8”, “from”: “[Colin.Mackenzie@company.com](mailto:Colin.Mackenzie@company.com)”, “headers”: null, “host”: “localhost”, “password”: null, “port”: “25”, “sender”: “[blah.Blah@company.com](mailto:blah.Blah@company.com)”, “subject”: Compnay WFI Report – Automated email", “subtype”: “plain”, “to”: “[Blah2.Blah0@company.com](mailto:Blah2.Blah0@company.com), [Blah1.Blah1@company.com](mailto:Blah1.Blah1@company.com), [Blah2.Blah2@company.com](mailto:Blah2.Blah2@company.com)”, “username”: null}, “module\_name”: “mail”}, “msg”: “Failed to send mail to server localhost on port 25: [Errno 61] Connection refused”, “rc”: 1}

I can send email fine from the command line like this:

uuencode /Users/mackc/ansible/reports/areport areport | mail -s “Company Report” [colin.mackenzie@company.com](mailto:colin.mackenzie@company.com)

What am i missing so i can send email from ansible playbook i have?  
Thanks for anyone taking the time to respond.

-cm3

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [June 2, 2016, 3:06pm UTC](https://forum.ansible.com/t/connection-refused-when-sending-mail-with-ansible/21642/2 "2016-06-02T15:06:29Z")

</div>

I think you are using ansible's mail module as a local action, while  
on the command line you are using the mail executable. And I guess the  
latter works without a fully configured SMTP-server on your macbook...

Can you use the full path to the mail executable in the local\_action?  
I'll have a look at the docs.

Johannes

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [June 2, 2016, 3:11pm UTC](https://forum.ansible.com/t/connection-refused-when-sending-mail-with-ansible/21642/3 "2016-06-02T15:11:02Z")

</div>

I guess not.

What happens when you test the following:

- hosts: localhost  
&nbsp;&nbsp;become: no  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- mail: ...

This should send a mail via ansible from your localhost. If this  
works, the local\_action should also work, I guess.

(Untested)

Johannes

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 2, 2016, 5:17pm UTC](https://forum.ansible.com/t/connection-refused-when-sending-mail-with-ansible/21642/4 "2016-06-02T17:17:06Z")

</div>

The mail command can invoke /usr/bin/sendmail directly and queue w/o having an MTA listening on port 25. The mail module needs a network accessible MTA (mail transfer agent, the software that actually accepts and delivers email).
