# Issue in configuring mail server

**URL:** <https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [September 2, 2015, 9:03pm UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557 "2015-09-02T21:03:44Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![NiteshBarnwal](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiteshBarnwal](https://discuss.elastic.co/u/NiteshBarnwal)\
**Post date:** [September 2, 2015, 9:03pm UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/1 "2015-09-02T21:03:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![uboness](https://avatars.discourse-cdn.com/v4/letter/u/96bed5/32.png) [@uboness](https://discuss.elastic.co/u/uboness)\
**Post date:** [September 2, 2015, 9:31pm UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/2 "2015-09-02T21:31:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![NiteshBarnwal](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiteshBarnwal](https://discuss.elastic.co/u/NiteshBarnwal)\
**Post date:** [September 2, 2015, 10:17pm UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/3 "2015-09-02T22:17:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![NiteshBarnwal](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiteshBarnwal](https://discuss.elastic.co/u/NiteshBarnwal)\
**Post date:** [September 3, 2015, 6:32pm UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/4 "2015-09-03T18:32:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![uboness](https://avatars.discourse-cdn.com/v4/letter/u/96bed5/32.png) [@uboness](https://discuss.elastic.co/u/uboness)\
**Post date:** [September 3, 2015, 8:01pm UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/5 "2015-09-03T20:01:56Z")

</div>

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

> [@NiteshBarnwal](#):
>
> java.net.UnknownHostException: exchange\_server

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

---

<div class="post-metadata">

**Author:** ![NiteshBarnwal](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiteshBarnwal](https://discuss.elastic.co/u/NiteshBarnwal)\
**Post date:** [September 4, 2015, 5:38am UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/6 "2015-09-04T05:38:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![uboness](https://avatars.discourse-cdn.com/v4/letter/u/96bed5/32.png) [@uboness](https://discuss.elastic.co/u/uboness)\
**Post date:** [September 4, 2015, 7:46am UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/7 "2015-09-04T07:46:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![NiteshBarnwal](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiteshBarnwal](https://discuss.elastic.co/u/NiteshBarnwal)\
**Post date:** [September 4, 2015, 8:09am UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/8 "2015-09-04T08:09:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![NiteshBarnwal](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiteshBarnwal](https://discuss.elastic.co/u/NiteshBarnwal)\
**Post date:** [September 4, 2015, 11:28am UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/9 "2015-09-04T11:28:50Z")

</div>

It got resolved.. worked as expected. Thank you Uri 😄

---

<div class="post-metadata">

**Author:** ![uboness](https://avatars.discourse-cdn.com/v4/letter/u/96bed5/32.png) [@uboness](https://discuss.elastic.co/u/uboness)\
**Post date:** [September 4, 2015, 12:02pm UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/10 "2015-09-04T12:02:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![NiteshBarnwal](https://avatars.discourse-cdn.com/v4/letter/n/e495f1/32.png) [@NiteshBarnwal](https://discuss.elastic.co/u/NiteshBarnwal)\
**Post date:** [September 4, 2015, 4:47pm UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/11 "2015-09-04T16:47:18Z")

</div>

exchange\_server was having some DNS issue.

---

<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 6, 2017, 1:48pm UTC](https://discuss.elastic.co/t/issue-in-configuring-mail-server/28557/12 "2017-07-06T13:48:45Z")

</div>


