# Watcher email html body passed as a stored script

**URL:** <https://discuss.elastic.co/t/watcher-email-html-body-passed-as-a-stored-script/183449>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [May 30, 2019, 2:37am UTC](https://discuss.elastic.co/t/watcher-email-html-body-passed-as-a-stored-script/183449 "2019-05-30T02:37:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NidOf3lp](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@NidOf3lp](https://discuss.elastic.co/u/NidOf3lp)\
**Post date:** [May 30, 2019, 2:37am UTC](https://discuss.elastic.co/t/watcher-email-html-body-passed-as-a-stored-script/183449/1 "2019-05-30T02:37:30Z")

</div>

Hi,

I'd like to have my email action to retrieve the email body stored as a mustache script. Currently the email get sent with "mem-watch-warning" as a text instead of the html content stored in \_scripts/mem-watch-warning.

Thanks for your help!

"actions": {  
"send\_mem\_warning": {  
"transform": {  
"script": {  
"lang": "painless",  
"source": "def latest = ctx.payload.aggregations.minutes.buckets[-1]; return latest.nodes.buckets.stream().filter(item -\> item.memory.value \>= ctx.metadata.threshold).collect(Collectors.toList());"  
}  
},  
"email": {  
"profile": "standard",  
"from": "watcher@your-company.com",  
"to": [  
"dude@your-company.com"  
],  
"subject": "Watcher Notification - HIGH MEMORY USAGE",  
"body": {  
"html": {  
**"id": "mem-watch-warning"**  
}  
}  
}  
}  
}

POST \_scripts/mem-watch-warning  
{  
"script": {  
"lang": "mustache",  
"source": "

## Nodes with HIGH MEMORY
Usage (above 60%):
{{#ctx.payload.\_value}}- "{{key}}" - Memory Usage is at {{memory.value}}
{{/ctx.payload.\_value}}
"  
}  
}

---

<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:** [May 31, 2019, 10:40am UTC](https://discuss.elastic.co/t/watcher-email-html-body-passed-as-a-stored-script/183449/2 "2019-05-31T10:40:45Z")

</div>

Hey,

this is not possible currently, as the body is a `TextTemplate` object, but not a script, see [https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/email/EmailTemplate.java#L33](https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/email/EmailTemplate.java#L33)

Feel free to open an enhancement issue in github for this though!

--Alex

---

<div class="post-metadata">

**Author:** ![NidOf3lp](https://avatars.discourse-cdn.com/v4/letter/n/c57346/32.png) [@NidOf3lp](https://discuss.elastic.co/u/NidOf3lp)\
**Post date:** [June 5, 2019, 3:47am UTC](https://discuss.elastic.co/t/watcher-email-html-body-passed-as-a-stored-script/183449/3 "2019-06-05T03:47:46Z")

</div>

Hi Alex,

I appreciate you took the time to look at my request.  
Thanks for your answer,

Cizz

---

<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:** [July 3, 2019, 3:47am UTC](https://discuss.elastic.co/t/watcher-email-html-body-passed-as-a-stored-script/183449/4 "2019-07-03T03:47:46Z")

</div>

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