# Ansible Tower - Mail callback plugin - Not sending emails correctly

**URL:** <https://forum.ansible.com/t/ansible-tower-mail-callback-plugin-not-sending-emails-correctly/21062>\
**Category:** Ansible Project\
**Created:** [April 4, 2016, 7:55pm UTC](https://forum.ansible.com/t/ansible-tower-mail-callback-plugin-not-sending-emails-correctly/21062 "2016-04-04T19:55:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chase\_Farrant](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Chase\_Farrant](https://forum.ansible.com/u/Chase_Farrant)\
**Post date:** [April 4, 2016, 7:55pm UTC](https://forum.ansible.com/t/ansible-tower-mail-callback-plugin-not-sending-emails-correctly/21062/1 "2016-04-04T19:55:44Z")

</div>

Hello all,

I am probably missing something here. I’m trying to get this mail plugin working - [https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/mail.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/mail.py)

If I edit the script by adding mail() to the end, I receive a basic email immediately with no information when I run a job template (I believe this is expected).

The problem is I never receive a summary email when the job is complete. My assumption is this is supposed to wait around until the job is completed, then send an email. As expected, I never receive an email at all if I remove the mail() command I appended to the mail.py script.

Does anyone have any insight in getting this to work?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 4, 2016, 8:14pm UTC](https://forum.ansible.com/t/ansible-tower-mail-callback-plugin-not-sending-emails-correctly/21062/2 "2016-04-04T20:14:09Z")

</div>

What you want to do is add a `def v2_playbook_on_stats(self, stats):` method, and put your summary emailing in there.

---

<div class="post-metadata">

**Author:** ![Chase\_Farrant](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Chase\_Farrant](https://forum.ansible.com/u/Chase_Farrant)\
**Post date:** [April 4, 2016, 8:34pm UTC](https://forum.ansible.com/t/ansible-tower-mail-callback-plugin-not-sending-emails-correctly/21062/3 "2016-04-04T20:34:33Z")

</div>

Wow that helped a bunch and clears up a bunch of questions I didn’t even know I had. Thanks!

---

<div class="post-metadata">

**Author:** ![Chase\_Farrant](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Chase\_Farrant](https://forum.ansible.com/u/Chase_Farrant)\
**Post date:** [April 4, 2016, 10:17pm UTC](https://forum.ansible.com/t/ansible-tower-mail-callback-plugin-not-sending-emails-correctly/21062/4 "2016-04-04T22:17:05Z")

</div>

Hmmm, it appears to still not be working.

I added that function with the mail() call I was using beforehand. No dice. If I move that call to the bottom of the script, it sends the email. It behaves as if none of the Callback functions are working. This also applies to the hipchat.py plugin I’ve been trying.

I also I tried creating both a ‘v2\_playbook\_on\_stats’ and ‘playbook\_on\_stats’ which didn’t change anything.

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel1](https://avatars.discourse-cdn.com/v4/letter/t/278dde/32.png) [@Timothy\_Appnel1](https://forum.ansible.com/u/Timothy_Appnel1)\
**Post date:** [April 4, 2016, 10:23pm UTC](https://forum.ansible.com/t/ansible-tower-mail-callback-plugin-not-sending-emails-correctly/21062/5 "2016-04-04T22:23:41Z")

</div>

Are you running v2? (Guessing so by @sivel’s suggestion.) Did you whitelist your callback in your config?

---

<div class="post-metadata">

**Author:** ![Chase\_Farrant](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Chase\_Farrant](https://forum.ansible.com/u/Chase_Farrant)\
**Post date:** [April 4, 2016, 10:42pm UTC](https://forum.ansible.com/t/ansible-tower-mail-callback-plugin-not-sending-emails-correctly/21062/6 "2016-04-04T22:42:21Z")

</div>

That fixed it! I had:

> bin\_ansible\_callbacks = true

I also needed to add:

> callback\_whitelist = mail

Also, not 100% sure on this - It appears hipchat.py needs to be updated to v2. [https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/hipchat.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/callback/hipchat.py)  
I tried whitelisting it as well, but received the following error message:

> ERROR! Unexpected Exception: ‘CallbackModule’ object has no attribute ‘display’ the full traceback was: Traceback (most recent call last): File “/usr/bin/ansible-playbook”, line 86, in sys.exit(cli.run()) File “/usr/lib/pymodules/python2.7/ansible/cli/playbook.py”, line 150, in run results = pbex.run() File “/usr/lib/pymodules/python2.7/ansible/executor/playbook\_executor.py”, line 79, in run self.\_tqm.load\_callbacks() File “/usr/lib/pymodules/python2.7/ansible/executor/task\_queue\_manager.py”, line 173, in load\_callbacks self.\_callback\_plugins.append(callback\_plugin()) File “/usr/lib/pymodules/python2.7/ansible/plugins/callback/hipchat.py”, line 70, in **init** self.display.warning('HipChat token could not be loaded. The HipChat ’ AttributeError: ‘CallbackModule’ object has no attribute ‘display’

I remember someone else ran into this with another plugin and it needed to be updated to v2 functions.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 4, 2016, 11:01pm UTC](https://forum.ansible.com/t/ansible-tower-mail-callback-plugin-not-sending-emails-correctly/21062/7 "2016-04-04T23:01:32Z")

</div>

As far as hipchat, you are correct. It was not fully updated for 2.0 and is not compatible at this time.

---

<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:** [April 5, 2016, 2:40am UTC](https://forum.ansible.com/t/ansible-tower-mail-callback-plugin-not-sending-emails-correctly/21062/8 "2016-04-05T02:40:47Z")

</div>

You should really not need to whitelist it unless it is shipped with ansible, only those modules have `CALLBACK_NEEDS_WHITELIST = True`​, any custom modules should not have that setting unless you explicitly want to force people to whitelist them for them to work.
