Issue in configuring mail server

I have configured actions as below:

"actions" : {
  "email_administrator" : {
    "email" : {
      "to" : "my_mail_id",
      "subject" : "Counts of error code is {{ctx.payload.hits.total}}",
      "body" : "There are total {{ctx.payload.hits.total}} error codes found at {{ctx.execution_time}}",
      "priority" : "high"
    }
  }
  }

Also I have the configuration in yml file as below:

watcher.actions.email.service.account:

   exchange_account:
        profile: outlook
        email_defaults:
            from: 'Watcher <root@hostname.com>'
        smtp:
            auth: true
            starttls.enable: true
            host: smtp-mail.outlook.com
            port: 587
            user: my_mail_id
            password: <Password>

I am getting below exception:

[2015-09-01 05:30:49,058][ERROR][watcher.actions.email    ] [Knickknack] failed to execute action [status_code_watch/email_administrator]
org.elasticsearch.watcher.actions.email.service.EmailSettingsException: cannot find default email account as no accounts have been configured
        at org.elasticsearch.watcher.actions.email.service.Accounts.account(Accounts.java:71)
        at org.elasticsearch.watcher.actions.email.service.InternalEmailService.send(InternalEmailService.java:74)
        at org.elasticsearch.watcher.actions.email.ExecutableEmailAction.execute(ExecutableEmailAction.java:67)
        at org.elasticsearch.watcher.actions.ActionWrapper.execute(ActionWrapper.java:104)
        at org.elasticsearch.watcher.execution.ExecutionService.executeInner(ExecutionService.java:379)
        at org.elasticsearch.watcher.execution.ExecutionService.execute(ExecutionService.java:271)
        at org.elasticsearch.watcher.execution.ExecutionService$WatchExecutionTask.run(ExecutionService.java:417)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

Any help on how it can be resolved?

The setup looks good... can you verify that these settings in elasticsearch.yml are identical on all nodes in the cluster?

Checked with GET _nodes/settings I can see; the mail comfiguration is present in one one only.
I have tried with below configuration also but no luck

watcher.actions.email.service.account:
    exchange:
        email_defaults:
            from: 'Watcher <root@hostname.com>' 
        profile: exchange
        smtp:
            auth: false
            starttls.enable: true
            host: $exchange_server
            port: 465

Is there anyway to make the configuration in sync with all nodes.

I stopped all instance of elasticsearch and started only one
Also I moved further with below account:

watcher.actions.email.service.account:
    exchange:
        email_defaults:
            from: 'Watcher <root@hostname.com>' 
        profile: exchange
        smtp:
            auth: false
            starttls.enable: true
            host: $exchange_server
            port: 25

Now I am getting as below:

org.elasticsearch.watcher.actions.email.service.EmailException: failed to send email with subject [Counts of error code is High] via account [exchange]
        at org.elasticsearch.watcher.actions.email.service.InternalEmailService.send(InternalEmailService.java:86)
        at org.elasticsearch.watcher.actions.email.service.InternalEmailService.send(InternalEmailService.java:78)
        at org.elasticsearch.watcher.actions.email.ExecutableEmailAction.execute(ExecutableEmailAction.java:67)
        at org.elasticsearch.watcher.actions.ActionWrapper.execute(ActionWrapper.java:104)
        at org.elasticsearch.watcher.execution.ExecutionService.executeInner(ExecutionService.java:379)
        at org.elasticsearch.watcher.execution.ExecutionService.execute(ExecutionService.java:271)
        at org.elasticsearch.watcher.execution.ExecutionService$WatchExecutionTask.run(ExecutionService.java:417)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: exchange_server, 25; timeout -1;
  nested exception is:
        java.net.UnknownHostException: exchange_server
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2054)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
        at javax.mail.Service.connect(Service.java:364)
        at org.elasticsearch.watcher.actions.email.service.Account.send(Account.java:99)
        at org.elasticsearch.watcher.actions.email.service.InternalEmailService.send(InternalEmailService.java:84)
        ... 9 more
Caused by: java.net.UnknownHostException: exchange_server
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)

Any idea what could be the issue; I am using correct smtp server

the good: the settings are now picked up
the bad:

looks like the $exchange_server var is not replaced with the actual host

I am not using any variable here.. its all static

Ok, for some reason, the host in the yml file is set to $exchange_server but watcher tries to connect to exchange_server... I can't really reproduce it tbh. Can you try to use another host (maybe IP address)?

As a side note, you can remove the profile setting as there is not exchange profile (it falls back to standard)... just for cleanup, that's not the root cause of the issue you're facing.

Thank you Uri for your time

sorry for the confusion, I am using $exchange_server is nothing but the alias i used here in the post.
I removed profile: exchange as suggested.

is it possible for you to give your mailid on which I can connect you for more details

It got resolved.. worked as expected. Thank you Uri :smile:

good to hear that... what was the problem?

exchange_server was having some DNS issue.