# Ansible Mail Module works on command line but Failing from AWX

**URL:** <https://forum.ansible.com/t/ansible-mail-module-works-on-command-line-but-failing-from-awx/30783>\
**Category:** AWX Project\
**Tags:** awx\
**Created:** [July 15, 2019, 12:24pm UTC](https://forum.ansible.com/t/ansible-mail-module-works-on-command-line-but-failing-from-awx/30783 "2019-07-15T12:24:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tirumalaraju\_Chandra](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@Tirumalaraju\_Chandra](https://forum.ansible.com/u/Tirumalaraju_Chandra)\
**Post date:** [July 15, 2019, 12:24pm UTC](https://forum.ansible.com/t/ansible-mail-module-works-on-command-line-but-failing-from-awx/30783/1 "2019-07-15T12:24:43Z")

</div>

The problem show up only when I use Ansible AWX to run playbook. There was no problem when I run the Anisble-palybook CLI.

I’m running a simple playbook to report on server configurations. I have a shell script to get system health check and then using mail module to send output of shell script into the body of the mail as follows:

**- name: Email Notification about health check**  
**mail:**  
**body: ‘{{ script\_output.stdout\_lines | to\_nice\_yaml }}’**  
**charset: utf8**  
**delegate\_to: localhost**  
**tags: hmail**

---

<div class="post-metadata">

**Author:** ![Tirumalaraju\_Chandra](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@Tirumalaraju\_Chandra](https://forum.ansible.com/u/Tirumalaraju_Chandra)\
**Post date:** [July 22, 2019, 8:20pm UTC](https://forum.ansible.com/t/ansible-mail-module-works-on-command-line-but-failing-from-awx/30783/2 "2019-07-22T20:20:17Z")

</div>

Can some one assist here?

---

<div class="post-metadata">

**Author:** ![Uriel](https://avatars.discourse-cdn.com/v4/letter/u/53a042/32.png) [@Uriel](https://forum.ansible.com/u/Uriel)\
**Post date:** [July 22, 2019, 9:55pm UTC](https://forum.ansible.com/t/ansible-mail-module-works-on-command-line-but-failing-from-awx/30783/3 "2019-07-22T21:55:59Z")

</div>

Can you post more information? What error message are you getting? What Ansible version are you running on CLI? What Ansible version are you running on AWX?

---

<div class="post-metadata">

**Author:** ![matburt](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/matburt/32/3612_2.png) [@matburt](https://forum.ansible.com/u/matburt)\
**Post date:** [July 23, 2019, 2:43pm UTC](https://forum.ansible.com/t/ansible-mail-module-works-on-command-line-but-failing-from-awx/30783/4 "2019-07-23T14:43:15Z")

</div>

Also, if this is running in the AWX container it’s entirely possible that those are just dead lettered automatically. You should see if the built in mail facilities even work at all in the container. The mail module in Ansible (and the Tower mail notification type) can both take upstream smtp server connection information. Sometimes traditional mail sending is blocked by ISPs and hosting providers (Amazon will block outgoing port 25 on ec2 hosts for example). It looks like you are just trying to send it out through local mail facilities which, like I said, may just plain not work from the AWX container.

There are many reasons a system can’t deliver mail, I’d exhaust all of those before I believe there is a bug in AWX.

---

<div class="post-metadata">

**Author:** ![Tirumalaraju\_Chandra](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@Tirumalaraju\_Chandra](https://forum.ansible.com/u/Tirumalaraju_Chandra)\
**Post date:** [July 23, 2019, 2:59pm UTC](https://forum.ansible.com/t/ansible-mail-module-works-on-command-line-but-failing-from-awx/30783/5 "2019-07-23T14:59:19Z")

</div>

The error was : socket.error: [Errno 111] Connection refused.

---

<div class="post-metadata">

**Author:** ![matburt](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/matburt/32/3612_2.png) [@matburt](https://forum.ansible.com/u/matburt)\
**Post date:** [July 23, 2019, 4:28pm UTC](https://forum.ansible.com/t/ansible-mail-module-works-on-command-line-but-failing-from-awx/30783/6 "2019-07-23T16:28:25Z")

</div>

There you go, you don’t have a local smtp server or it’s being blocked. You’ll need to fix that.

---

<div class="post-metadata">

**Author:** ![Tirumalaraju\_Chandra](https://avatars.discourse-cdn.com/v4/letter/t/eb9ed0/32.png) [@Tirumalaraju\_Chandra](https://forum.ansible.com/u/Tirumalaraju_Chandra)\
**Post date:** [July 23, 2019, 4:57pm UTC](https://forum.ansible.com/t/ansible-mail-module-works-on-command-line-but-failing-from-awx/30783/7 "2019-07-23T16:57:40Z")

</div>

Thanks for your response.

I do receive email from the client machine when I run the same playbook using ansible-playbook command line. This happens only when I execute from AWX.  
And port 25 is open on the client server. You mean, should I configure postfix on awx web docker?

---

<div class="post-metadata">

**Author:** ![Mike\_Charchuk](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Mike\_Charchuk](https://forum.ansible.com/u/Mike_Charchuk)\
**Post date:** [July 23, 2019, 5:03pm UTC](https://forum.ansible.com/t/ansible-mail-module-works-on-command-line-but-failing-from-awx/30783/8 "2019-07-23T17:03:36Z")

</div>

You may want to specify the smtp server in the mail message with the host parameter.
