# Cannot set up email alert in Watcher

**URL:** <https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [December 23, 2017, 4:04pm UTC](https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081 "2017-12-23T16:04:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SIJIA\_CHEN](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@SIJIA\_CHEN](https://discuss.elastic.co/u/SIJIA_CHEN)\
**Post date:** [December 23, 2017, 4:04pm UTC](https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081/1 "2017-12-23T16:04:35Z")

</div>

Hi，

I installed x-pack (both in Elasticsearch and Kibana, and also restarted all services) and tried to set an email alert by using watcher. However, when I clicked "test fire email", it gave me error showing " Watcher: Cannot read property 'message' of null" and then the browser forced me to quit the page and had to re-login. Couple weird things happened when I have been doing the watcher email alert configuration:

1. Every time when I installed x-pack ( I have tried install ELK in both CentOS and Ubuntu), the Kibana would just stop to receive any information from metricbeats and showed "no result found " page.
2. The last time I set this alert configuration, it showed me different error, which was "MessagingException: can't determine local email address"

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/d/1df093705c9cb634809afd311f0e44ba098ae92e.png)

Does anyone have any idea what is the problem? Thanks!

---

<div class="post-metadata">

**Author:** ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)\
**Post date:** [December 29, 2017, 12:04pm UTC](https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081/2 "2017-12-29T12:04:19Z")

</div>

Hi,

Couple of questions: Which version of ES/Kibana you are on?  
Did you set up your email alerts in Elasticsearch.yml?

[https://www.elastic.co/guide/en/x-pack/current/actions-email.html#configuring-email-attachments](https://www.elastic.co/guide/en/x-pack/current/actions-email.html#configuring-email-attachments)

Thanks,  
Bhavya

---

<div class="post-metadata">

**Author:** ![DaveyDevOps](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daveydevops/32/57124_2.png) [@DaveyDevOps](https://discuss.elastic.co/u/DaveyDevOps)\
**Post date:** [December 29, 2017, 1:08pm UTC](https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081/3 "2017-12-29T13:08:50Z")

</div>

I saw something like this yesterday. For me, I had to specify the "profile" to match the email account specified in Elasticsearch.yml when configuring the email action of the watch.

```auto
"actions" : {
  "send_email" : { 
    "email" : { 
      "profile": "outlook"
      "to" : "<username>@<domainname>", 
      "subject" : "Watcher Notification", 
      "body" : "{{ctx.payload.hits.total}} error logs found" 
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![SIJIA\_CHEN](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@SIJIA\_CHEN](https://discuss.elastic.co/u/SIJIA_CHEN)\
**Post date:** [December 30, 2017, 12:07am UTC](https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081/4 "2017-12-30T00:07:46Z")

</div>

Hi Bhavya,

Thanks for your reply!

I am using all the newest version ES/Kibana/Metricbeat, which is 6.1. I did set the gmail email setting in elasticsearch.yml by following the reference. Actually, my gmail can get the security alert once I was trying to test the email configuration in watch, which means the elasticsearch was able to communicate with the gmail. But once I lowered the security configuration in gmail, it popped up another error, which was showing in the picture..

Thanks,  
Chen

---

<div class="post-metadata">

**Author:** ![SIJIA\_CHEN](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@SIJIA\_CHEN](https://discuss.elastic.co/u/SIJIA_CHEN)\
**Post date:** [December 30, 2017, 12:17am UTC](https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081/5 "2017-12-30T00:17:26Z")

</div>

Hi David,

Thanks for your reply!

Actually, I am quite new to Elasticsearch, so what I did just follow the reference. And according to the reference, the only configuration I did in Elasticserach.yml was that I added the following :

xpack.notification.email.account:  
gmail\_account:  
profile: gmail  
smtp:  
auth: true  
starttls.enable: true  
host: [smtp.gmail.com](http://smtp.gmail.com)  
port: 587  
user:   
password:

So do you mean I need to add the "actions", which you quoted, to the elasticsearch.yml in order to trigger the email alert feature?

Thanks,

Chen

---

<div class="post-metadata">

**Author:** ![DaveyDevOps](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daveydevops/32/57124_2.png) [@DaveyDevOps](https://discuss.elastic.co/u/DaveyDevOps)\
**Post date:** [December 30, 2017, 4:43pm UTC](https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081/6 "2017-12-30T16:43:17Z")

</div>

My suggestion would be to add "profile" : "gmail" into the email action of the watch. That should be the only additional parameter.

Can you clarify what this involved?

> [@SIJIA\_CHEN](#):
>
> But once I lowered the security configuration in gmail

---

<div class="post-metadata">

**Author:** ![SIJIA\_CHEN](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@SIJIA\_CHEN](https://discuss.elastic.co/u/SIJIA_CHEN)\
**Post date:** [January 2, 2018, 3:05am UTC](https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081/7 "2018-01-02T03:05:49Z")

</div>

Hi David,

Thanks for getting back to me!

Actually I was not quite familiar with some basic API operation, such as add the action. The error I got occurred when I set the watch configuration on Kibana webpage by clicking"Test fire an e-mail now" button ... But today, I tried to add a watch by using API method, the email alert worked! My gmail got the email from Elasticsearch. So I am assuming the problem is the testing feature, not the email setting. I just post the action I successfully executed for reference. Again, thanks for your help. Really appreciate!

"actions" : {  
"my\_webhook" : {  
"webhook" : {  
"method" : "POST",  
"host" : "mylisteninghost",  
"port" : 9200,  
"path" : "/{{watch\_id}}",  
"body" : "Encountered {{ctx.payload.hits.total}} errors"  
}  
},  
"email\_administrator" : {  
"email" : {  
"to" : "xxxxxxxx@gmail.com",  
"subject" : "Encountered {{ctx.payload.hits.total}} errors",  
"body" : "Too many error in the system, see attached data",  
"attachments" : {  
"attached\_data" : {  
"data" : {  
"format" : "json"  
}  
}  
},  
"priority" : "high"  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![SIJIA\_CHEN](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@SIJIA\_CHEN](https://discuss.elastic.co/u/SIJIA_CHEN)\
**Post date:** [January 2, 2018, 3:11am UTC](https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081/8 "2018-01-02T03:11:44Z")

</div>

I think I solved the problem. The reason I couldn't get any metricbeat info after instaling x-pack was I didn't set username and password in metribeat.yml . And the error I got when I was trying to send a "test email" still exists, however, it is able to send an alert email when I set an appropriate action. So I just ignore the error.

---

<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:** [January 30, 2018, 3:12am UTC](https://discuss.elastic.co/t/cannot-set-up-email-alert-in-watcher/113081/9 "2018-01-30T03:12:19Z")

</div>

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