Elasticsearch watcher cannot to connect smtp host

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

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

{
  "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

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

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

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.

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

telnet smtp.gmail.com 587

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

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