# Elasticsearch watcher cannot to connect smtp host

**URL:** https://discuss.elastic.co/t/elasticsearch-watcher-cannot-to-connect-smtp-host/173873
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [March 26, 2019, 7:57am UTC](https://discuss.elastic.co/t/elasticsearch-watcher-cannot-to-connect-smtp-host/173873 "2019-03-26T07:57:57Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ZMMWMY](https://avatars.discourse-cdn.com/v4/letter/z/a587f6/32.png) [@ZMMWMY](https://discuss.elastic.co/u/ZMMWMY)
#### Post date: [March 26, 2019, 7:57am UTC](https://discuss.elastic.co/t/elasticsearch-watcher-cannot-to-connect-smtp-host/173873/1 "2019-03-26T07:57:58Z")

</div>

i am using es 6.2.3 and i have configured watcher ,set up email configuration in **elasticsearch.yml**

```auto
xpack.notification.email:
 default_account: smtp_account
 account:
   smtp_account:
     profile: standard
     smtp:
       auth: true
       starttls.enable: true
       host: smtp.163.com
       port: 587
       user: xx@163.com
       password: xx

```

**watcher configuration**

```auto
{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "*"
        ],
        "types": [],
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "must": [
                {
                  "match": {
                    "level": {
                      "query": "error"
                    }
                  }
                },
                {
                  "range": {
                    "@timestamp": {
                      "gte": "now-1m"
                    }
                  }
                }
              ]
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 3
      }
    }
  },
  "actions": {
    "send_email": {
      "email": {
        "profile": "outlook",
        "to": [
          "xx@outlook.com"
        ],
        "subject": "Watcher Notification",
        "body": {
          "text": " error logs found"
        }
      }
    }
  }
}

```

**the error log**

```auto
javax.mail.MessagingException: failed to send email with subject [Watcher Notification] via account [smtp_account]
        at org.elasticsearch.xpack.watcher.notification.email.EmailService.send(EmailService.java:112) ~[?:?]
        at org.elasticsearch.xpack.watcher.notification.email.EmailService.send(EmailService.java:104) ~[?:?]
        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.3.jar:6.2.3]
        at org.elasticsearch.xpack.watcher.execution.ExecutionService.executeInner(ExecutionService.java:492) ~[x-pack-watcher-6.2.3.jar:6.2.3]
        at org.elasticsearch.xpack.watcher.execution.ExecutionService.execute(ExecutionService.java:322) ~[x-pack-watcher-6.2.3.jar:6.2.3]
        at org.elasticsearch.xpack.watcher.execution.ExecutionService.lambda$executeAsync$7(ExecutionService.java:426) ~[x-pack-watcher-6.2.3.jar:6.2.3]
        at org.elasticsearch.xpack.watcher.execution.ExecutionService$WatchExecutionTask.run(ExecutionService.java:580) [x-pack-watcher-6.2.3.jar:6.2.3]
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:573) [elasticsearch-6.2.3.jar:6.2.3]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_161]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_161]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_161]
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.163.com, port: 587, response: -1
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2106) ~[?:?]
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712) ~[?:?]
        at javax.mail.Service.connect(Service.java:366) ~[?:?]
        at org.elasticsearch.xpack.watcher.notification.email.Account.lambda$executeConnect$2(Account.java:166) ~[?:?]
        at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_161]
        at org.elasticsearch.xpack.watcher.notification.email.Account.executeConnect(Account.java:165) ~[?:?]

```

please help me  
Thanks

---

<div class="post-metadata">

### Author: ![ZMMWMY](https://avatars.discourse-cdn.com/v4/letter/z/a587f6/32.png) [@ZMMWMY](https://discuss.elastic.co/u/ZMMWMY)
#### Post date: [March 26, 2019, 10:44am UTC](https://discuss.elastic.co/t/elasticsearch-watcher-cannot-to-connect-smtp-host/173873/2 "2019-03-26T10:44:28Z")

</div>

i try gmail and outlook email , still do not work.  
but i use telnet command ,it can connected , i am so confused

---

<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: [March 26, 2019, 12:40pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-cannot-to-connect-smtp-host/173873/3 "2019-03-26T12:40:05Z")

</div>

the exception states that there is an issue connecting to the endpoint. Can you share the telnet session (without user accounts/passwords) that shows you how send an email? Maybe the other side is dropping the connection after it has been created out of whatever reason.

---

<div class="post-metadata">

### Author: ![ZMMWMY](https://avatars.discourse-cdn.com/v4/letter/z/a587f6/32.png) [@ZMMWMY](https://discuss.elastic.co/u/ZMMWMY)
#### Post date: [March 26, 2019, 2:26pm UTC](https://discuss.elastic.co/t/elasticsearch-watcher-cannot-to-connect-smtp-host/173873/4 "2019-03-26T14:26:01Z")

</div>

i just use telnet commend to test the port ,i know it is stupid but i do not know what other ways available

```auto
telnet smtp.gmail.com 587

```

---

<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: [April 1, 2019, 7:11am UTC](https://discuss.elastic.co/t/elasticsearch-watcher-cannot-to-connect-smtp-host/173873/5 "2019-04-01T07:11:16Z")

</div>

telnet just checks if the TCP connection is working, but does not guarantee you that sending an email actually works. You should check for that as well!

--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: [April 29, 2019, 7:11am UTC](https://discuss.elastic.co/t/elasticsearch-watcher-cannot-to-connect-smtp-host/173873/6 "2019-04-29T07:11:17Z")

</div>

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