# Sending email while Alert

**URL:** <https://discuss.elastic.co/t/sending-email-while-alert/135950>\
**Category:** Elasticsearch\
**Created:** [June 14, 2018, 3:02pm UTC](https://discuss.elastic.co/t/sending-email-while-alert/135950 "2018-06-14T15:02:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![elleuch](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@elleuch](https://discuss.elastic.co/u/elleuch)\
**Post date:** [June 14, 2018, 3:02pm UTC](https://discuss.elastic.co/t/sending-email-while-alert/135950/1 "2018-06-14T15:02:42Z")

</div>

I want to send emails with watcher menu in Kibana. I tried a configuration in elasticsarch.yml and I don't know why it never arrived to send emails. What should I write in the elasticsearch.yml? and shoud I add another thing in an other file to activate watcher.  
Thank you.

This is my code :  
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:

ps: I don't know what to write in user and password

---

<div class="post-metadata">

**Author:** ![richcollier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richcollier/32/115035_2.png) [@richcollier](https://discuss.elastic.co/u/richcollier)\
**Post date:** [June 15, 2018, 1:11am UTC](https://discuss.elastic.co/t/sending-email-while-alert/135950/2 "2018-06-15T01:11:29Z")

</div>

It's the username and password of the gmail account that you want to use to send the email from.

(I assume you have a gmail account that you can use for this purpose)

---

<div class="post-metadata">

**Author:** ![elleuch](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@elleuch](https://discuss.elastic.co/u/elleuch)\
**Post date:** [June 15, 2018, 7:42am UTC](https://discuss.elastic.co/t/sending-email-while-alert/135950/3 "2018-06-15T07:42:00Z")

</div>

Yes I had them. I printed them and then when I send an email for someone else, it mentionned an error with watcher.

 ![Capture%20du%202018-06-15%2009-40-41](https://us1.discourse-cdn.com/elastic/original/3X/6/7/67bd2ea268d0d65d0a8646ed7faa996b95da53d8.png)

---

<div class="post-metadata">

**Author:** ![richcollier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richcollier/32/115035_2.png) [@richcollier](https://discuss.elastic.co/u/richcollier)\
**Post date:** [June 15, 2018, 12:35pm UTC](https://discuss.elastic.co/t/sending-email-while-alert/135950/4 "2018-06-15T12:35:36Z")

</div>

It's a little hard to help without knowing what you actually put in your elasticsarch.yml configuration or what you put in your [email action](https://www.elastic.co/guide/en/x-pack/current/actions-email.html) or your watch, or the relevant output of the elasticsearch.log file where surely more detailed error messages occur.

So, feel free to provide those (and redact sensitive information as necessary).

Also, there are plenty of others who've encountered the same questions. Might be good to look through these:

[https://discuss.elastic.co/search?q=%22failed%20to%20send%20email%22%20gmail](https://discuss.elastic.co/search?q=%22failed%20to%20send%20email%22%20gmail)

The most probable answer is that you've not enabled your gmail to send email from 3rd party apps.

---

<div class="post-metadata">

**Author:** ![elleuch](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@elleuch](https://discuss.elastic.co/u/elleuch)\
**Post date:** [June 15, 2018, 12:42pm UTC](https://discuss.elastic.co/t/sending-email-while-alert/135950/5 "2018-06-15T12:42:00Z")

</div>

Thank you for you answer.  
this is my elasticserach.yml :

xpack.watcher.enabled : true  
action.auto\_create\_index: .watches,.triggered\_watches,.watcher-history\*

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: \*\*\*\*\*

How can I enable gmail to send email from 3rd party apps?

As I am strating learning ELK stack, Watcher can be send from Kibana directly. Is there something should be configured to enable watchers?

Or should I print the watches just like :  
"actions" : {  
"send\_email" : {  
"email" : {  
"to" : "@",  
"subject" : "Watcher Notification",  
"body" : "{{ctx.payload.hits.total}} error logs found"  
}  
}  
}

Thank you.

---

<div class="post-metadata">

**Author:** ![richcollier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/richcollier/32/115035_2.png) [@richcollier](https://discuss.elastic.co/u/richcollier)\
**Post date:** [June 15, 2018, 12:48pm UTC](https://discuss.elastic.co/t/sending-email-while-alert/135950/6 "2018-06-15T12:48:45Z")

</div>

Please also include the relevant errors seen in elasticsearch.log.

Information on gmail external access via IMAP and troubleshooting:

[https://support.google.com/mail/answer/7126229](https://support.google.com/mail/answer/7126229)

---

<div class="post-metadata">

**Author:** ![elleuch](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@elleuch](https://discuss.elastic.co/u/elleuch)\
**Post date:** [June 15, 2018, 12:52pm UTC](https://discuss.elastic.co/t/sending-email-while-alert/135950/7 "2018-06-15T12:52:08Z")

</div>

I think it is a problem in configuration in gmail account. I will take a look.  
By the way, here is the error :

[2018-06-15T14:24:21,235][ERROR][o.e.x.w.a.e.ExecutableEmailAction] [Lh5V5GQ] failed to execute action [_inlined_/email\_1]  
javax.mail.MessagingException: failed to send email with subject [Watch [sdf] has exceeded the threshold] via account [gmail\_account]  
at org.elasticsearch.xpack.watcher.notification.email.EmailService.send(EmailService.java:154) ~[?:?]  
at org.elasticsearch.xpack.watcher.notification.email.EmailService.send(EmailService.java:146) ~[?:?]  
at org.elasticsearch.xpack.watcher.actions.email.ExecutableEmailAction.execute(ExecutableEmailAction.java:84) ~[?:?]  
at org.elasticsearch.xpack.core.watcher.actions.ActionWrapper.execute(ActionWrapper.java:156) [x-pack-core-6.2.4.jar:6.2.4]  
at org.elasticsearch.xpack.watcher.execution.ExecutionService.executeInner(ExecutionService.java:487) [x-pack-watcher-6.2.4.jar:6.2.4]  
at org.elasticsearch.xpack.watcher.execution.ExecutionService.execute(ExecutionService.java:317) [x-pack-watcher-6.2.4.jar:6.2.4]  
at org.elasticsearch.xpack.watcher.transport.actions.execute.TransportExecuteWatchAction$1.doRun(TransportExecuteWatchAction.java:165) [x-pack-watcher-6.2.4.jar:6.2.4]  
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.2.4.jar:6.2.4]  
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0\_171]  
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0\_171]  
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:573) [elasticsearch-6.2.4.jar:6.2.4]  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0\_171]  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0\_171]  
at java.lang.Thread.run(Thread.java:748) [?:1.8.0\_171]  
Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 \<[https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbtI](https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbtI)  
534-5.7.14 HDpnJShYt8gUgQzoASKg0B5ZMFt8c0eIQp4QPhDSOfaQBTZYpep4p5GObxQ57-XUmv20nT  
534-5.7.14 w94\_IgG43PHKlfSKqU\_a5gehv42PACc5zvI-7dixauKZEgXccF3-8Iw\_fbqH14Vo4Nh4TC  
534-5.7.14 hzvdMAGeXqUI6xsghmOEc5ZZIeeLepHwLmdvqPXaW5lth5kLhgfZOFhbvKvKQS4gjWhWdG  
534-5.7.14 QDqz-9ZcTnTtFjhIeeAA-EO5ume9E\> Please log in via your web browser and  
534-5.7.14 then try again.  
534-5.7.14 Learn more at  
534 5.7.14 [https://support.google.com/mail/answer/78754](https://support.google.com/mail/answer/78754) y8-v6sm9934645wrq.35 - gsmtp

```
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:932) ~[?:?]
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:843) ~[?:?]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:748) ~[?:?]
at javax.mail.Service.connect(Service.java:366) ~[?:?]
at org.elasticsearch.xpack.watcher.notification.email.Account.lambda$executeConnect$2(Account.java:165) ~[?:?]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_171]
at org.elasticsearch.xpack.watcher.notification.email.Account.executeConnect(Account.java:164) ~[?:?]
at org.elasticsearch.xpack.watcher.notification.email.Account.send(Account.java:123) ~[?:?]
at org.elasticsearch.xpack.watcher.notification.email.EmailService.send(EmailService.java:152) ~[?:?]
... 13 more

```

[2018-06-15T14:38:39,614][ERROR][o.e.x.w.a.e.ExecutableEmailAction] [Lh5V5GQ] failed to execute action [_inlined_/email\_1]  
javax.mail.MessagingException: failed to send email with subject [Watch [sdf] has exceeded the threshold] via account [gmail\_account]  
at org.elasticsearch.xpack.watcher.notification.email.EmailService.send(EmailService.java:154) ~[?:?]  
at org.elasticsearch.xpack.watcher.notification.email.EmailService.send(EmailService.java:146) ~[?:?]  
at org.elasticsearch.xpack.watcher.actions.email.ExecutableEmailAction.execute(ExecutableEmailAction.java:84) ~[?:?]  
at org.elasticsearch.xpack.core.watcher.actions.ActionWrapper.execute(ActionWrapper.java:156) [x-pack-core-6.2.4.jar:6.2.4]  
at org.elasticsearch.xpack.watcher.execution.ExecutionService.executeInner(ExecutionService.java:487) [x-pack-watcher-6.2.4.jar:6.2.4]  
at org.elasticsearch.xpack.watcher.execution.ExecutionService.execute(ExecutionService.java:317) [x-pack-watcher-6.2.4.jar:6.2.4]  
at org.elasticsearch.xpack.watcher.transport.actions.execute.TransportExecuteWatchAction$1.doRun(TransportExecuteWatchAction.java:165) [x-pack-watcher-6.2.4.jar:6.2.4]  
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-6.2.4.jar:6.2.4]  
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0\_171]  
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0\_171]  
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:573) [elasticsearch-6.2.4.jar:6.2.4]  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0\_171]  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0\_171]  
at java.lang.Thread.run(Thread.java:748) [?:1.8.0\_171]  
Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 \<[https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbuE](https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbuE)  
534-5.7.14 J6WrK60cif0Kn2jTqo-dBbTfFtuJCAGw6xHlfRSn2CHhknOoIOZ4Gy6HounAoswmLeNzg3  
534-5.7.14 690b4sdfEjugMR73n9LID6tTgbu0cE70f5EqRXQTWm33XGEfW5ZS9S6bX\_DhXVdXj6mPPn  
534-5.7.14 Y0mBAk7iK5TrwS4dOKV8ZnuZ7yBrL6ZMgUD5sWmr4psLRtuE5jXpDucOvpg2aDCzMp9BQ\_  
534-5.7.14 r7wChHkgQoW8s5OHg0oKHxaF3UZZU\> Please log in via your web browser and  
534-5.7.14 then try again.  
534-5.7.14 Learn more at  
534 5.7.14 [https://support.google.com/mail/answer/78754](https://support.google.com/mail/answer/78754) n12-v6sm6924675wrp.69 - gsmtp

```
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:932) ~[?:?]
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:843) ~[?:?]
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:748) ~[?:?]
at javax.mail.Service.connect(Service.java:366) ~[?:?]
at org.elasticsearch.xpack.watcher.notification.email.Account.lambda$executeConnect$2(Account.java:165) ~[?:?]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_171]
at org.elasticsearch.xpack.watcher.notification.email.Account.executeConnect(Account.java:164) ~[?:?]
at org.elasticsearch.xpack.watcher.notification.email.Account.send(Account.java:123) ~[?:?]
at org.elasticsearch.xpack.watcher.notification.email.EmailService.send(EmailService.java:152) ~[?:?]
```

---

<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:** [June 22, 2018, 2:18pm UTC](https://discuss.elastic.co/t/sending-email-while-alert/135950/8 "2018-06-22T14:18:09Z")

</div>

please check the exception that also includes a link to google support, especially if you are using 2FA, two factor authentication. Authentication did not work as expected, which requires you to do some more steps to set up everything properly on the google side.

Hope this helps!

--Alex

---

<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 20, 2018, 2:18pm UTC](https://discuss.elastic.co/t/sending-email-while-alert/135950/9 "2018-07-20T14:18:10Z")

</div>

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