# X-Pack Watcher: multiple emails in to/cc fields via template

**URL:** <https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058>\
**Category:** Elasticsearch\
**Created:** [February 22, 2017, 2:40pm UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058 "2017-02-22T14:40:55Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sova](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sova/32/13984_2.png) [@sova](https://discuss.elastic.co/u/sova)\
**Post date:** [February 22, 2017, 2:40pm UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/1 "2017-02-22T14:40:55Z")

</div>

Hello all,  
Brief intro: I'm creating watcher alerts with send email actions.  
Email fields TO and CC are calculatable, so known only after watch execution and can be transformed before the action.  
As noted in the documentation here to field can be either array or email address from template [https://www.elastic.co/guide/en/x-pack/current/actions-email.html#email-action-attributes](https://www.elastic.co/guide/en/x-pack/current/actions-email.html#email-action-attributes) .

Am I right, that I have no chance to format an output with Mustache template with several emails to be successfully executed?  
Or there is some hidden feature inside?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 22, 2017, 3:00pm UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/2 "2017-02-22T15:00:15Z")

</div>

Hey,

a possible trick here might be to have an array of email addresses, that are concatenated using the mustache `{{join}}` operator, that was added recently.

```auto
"to" : "{{#join}}ctx.payload.emails{{/join}}"

```

See [https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html#\_concatenating\_array\_of\_values](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html#_concatenating_array_of_values)

--Alex

---

<div class="post-metadata">

**Author:** ![sova](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sova/32/13984_2.png) [@sova](https://discuss.elastic.co/u/sova)\
**Post date:** [February 22, 2017, 5:44pm UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/3 "2017-02-22T17:44:10Z")

</div>

Hi Alexander,  
Thank you for the idea.  
However according to the documentation it's still about rendering data as string, so I can just replace it with  
`"to": "email1@mail.com,email2@mail.com"` to receive the same result.  
And in such cases I receive `Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 501 5.1.3 Invalid address` exception from mail client

--Sergey

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 23, 2017, 8:08am UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/4 "2017-02-23T08:08:31Z")

</div>

Hey,

sorry, that was me typing late in the evening. I thought this works, but it does not. I do not have any better idea for now, other that storing the info statically in the watch `metadata`. I assume you will get that information during the execution? Can you explain your use-case?

--Alex

---

<div class="post-metadata">

**Author:** ![sova](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sova/32/13984_2.png) [@sova](https://discuss.elastic.co/u/sova)\
**Post date:** [February 27, 2017, 2:27pm UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/5 "2017-02-27T14:27:41Z")

</div>

Hi,  
Regarding `metadata` I guess it won't work for my use case, please check it below.

Some time ago I've extracted tasks from a bug tracker (JIRA) to elastic, connected with Kibana and everything is perfect.  
Now I'm trying to integrate watcher in the process to automatically control issue attributes.  
For example use-case: search in elastic issues with invalid label, then send email notification to assignees keeping informed team leamer and project manager.

In transform section I can calculate array of issue assignees as well as dynamic list of team leaders emails, however I wasn't able to provide this info as an recipients array via templating.  
So before search query execution I don't know recipient list.

Thanks,  
Sergey

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 27, 2017, 8:37pm UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/6 "2017-02-27T20:37:29Z")

</div>

Hey,

so I dug a bit and it seems there is support for comma separated email addresses in the email component, except for one place, where it is not supported. I will try to add this as soon as possible. Will keep you posted!

--Alex

---

<div class="post-metadata">

**Author:** ![sova](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sova/32/13984_2.png) [@sova](https://discuss.elastic.co/u/sova)\
**Post date:** [March 21, 2017, 11:10am UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/7 "2017-03-21T11:10:24Z")

</div>

Hi Alex,  
Is there any updates on this topic or may be you have some public issue tracker to subscribe on updates?

Thanks,  
Sergey

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 18, 2017, 11:10am UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/8 "2017-04-18T11:10:33Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)\
**Post date:** [October 9, 2017, 7:45pm UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/9 "2017-10-09T19:45:23Z")

</div>



---

<div class="post-metadata">

**Author:** ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)\
**Post date:** [October 9, 2017, 7:46pm UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/10 "2017-10-09T19:46:54Z")

</div>

@pabloc Please ask your question here.

Thanks,  
Lee

---

<div class="post-metadata">

**Author:** ![pabloc](https://avatars.discourse-cdn.com/v4/letter/p/bcef8e/32.png) [@pabloc](https://discuss.elastic.co/u/pabloc)\
**Post date:** [October 15, 2017, 11:45am UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/11 "2017-10-15T11:45:35Z")

</div>

Hi,  
I'm running version 2.4.1 and having the same problem with multiple email addresses in a Mustache template.

Any news on this topic?

Thank you,  
Pablo

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 16, 2017, 9:11am UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/12 "2017-10-16T09:11:09Z")

</div>

This is fixed in 5.4.0 onwards.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 4, 2022, 4:39am UTC](https://discuss.elastic.co/t/x-pack-watcher-multiple-emails-in-to-cc-fields-via-template/76058/13 "2022-11-04T04:39:52Z")

</div>


