# Logstash doesn't send any emails

**URL:** <https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967>\
**Category:** Logstash\
**Created:** [July 5, 2017, 5:53pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967 "2017-07-05T17:53:17Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob04](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@Bob04](https://discuss.elastic.co/u/Bob04)\
**Post date:** [July 5, 2017, 5:53pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/1 "2017-07-05T17:53:17Z")

</div>

I am using Logstash-email output with the following configuration:

```
  email {
    to => "..."
    subject => "..."
    port => 25
    via => "smtp"
    body => "%{message}"
  }

```

But I didn't receive any email.

`telnet localhost 25` shows this:

```
# telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 <host_name> ESMTP Postfix

```

Are there any errors in my config file?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 5, 2017, 5:58pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/2 "2017-07-05T17:58:47Z")

</div>

If Logstash has problems sending email it'll tell you about it in its log.

---

<div class="post-metadata">

**Author:** ![Bob04](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@Bob04](https://discuss.elastic.co/u/Bob04)\
**Post date:** [July 5, 2017, 6:00pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/3 "2017-07-05T18:00:22Z")

</div>

I checked the logs and didn't find any error messages there.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 5, 2017, 6:02pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/4 "2017-07-05T18:02:02Z")

</div>

And how do you know your events even reach the output? Also, have you tried increasing Logstash's log level to get more entries in the log?

---

<div class="post-metadata">

**Author:** ![Bob04](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@Bob04](https://discuss.elastic.co/u/Bob04)\
**Post date:** [July 5, 2017, 6:03pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/5 "2017-07-05T18:03:42Z")

</div>

I am also using `Elasticsearch` output and `stdout { codec => rubydebug }` and I can see new messages are coming.

---

<div class="post-metadata">

**Author:** ![Bob04](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@Bob04](https://discuss.elastic.co/u/Bob04)\
**Post date:** [July 5, 2017, 6:15pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/6 "2017-07-05T18:15:36Z")

</div>

I found this error in Logstash logs:

```
12:27:29.769 [[main]>worker0] ERROR logstash.outputs.email - Something happen while delivering an email {:exception=>#<Errno::ECONNREFUSED: Connection refused - Connection refused>}
12:27:30.044 [[main]>worker0] ERROR logstash.outputs.email - Something happen while delivering an email {:exception=>#<Errno::ECONNREFUSED: Connection refused - Connection refused>}

```

I am able to send and receive email from terminal, though:

`mailx -v -s "email_subject" <send_to_address>`

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 5, 2017, 7:24pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/7 "2017-07-05T19:24:01Z")

</div>

> Errno::ECONNREFUSED: Connection refused - Connection refused

This certainly suggests that nobody's listening on localhost:25. Is Postfix perhaps only listening on the IPv6 interface an Logstash only support IPv4? That could explain why "telnet localhost 25" works and seemingly does so by connecting to ::1.

> I am able to send and receive email from terminal, though:

mailx doesn't use SMTP.

---

<div class="post-metadata">

**Author:** ![Bob04](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@Bob04](https://discuss.elastic.co/u/Bob04)\
**Post date:** [July 5, 2017, 7:28pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/8 "2017-07-05T19:28:56Z")

</div>

Thanks for explanation.  
Is there any way to fix that problem to be able to receive emails from Logstash?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 5, 2017, 7:32pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/9 "2017-07-05T19:32:41Z")

</div>

That's a Postfix question, but check the [inet\_protocols](http://www.postfix.org/postconf.5.html#inet_protocols) parameter in /etc/postfix/main.cf.

---

<div class="post-metadata">

**Author:** ![Bob04](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@Bob04](https://discuss.elastic.co/u/Bob04)\
**Post date:** [July 5, 2017, 7:45pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/10 "2017-07-05T19:45:21Z")

</div>

In /etc/postfix/main.cf I can see all `inet_protocols` are enabled:

```
# Enable IPv4, and IPv6 if supported
inet_protocols = all
```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 6, 2017, 8:52am UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/11 "2017-07-06T08:52:05Z")

</div>

And _is_ Postfix actually listening on 127.0.0.1:25? Does "telnet 127.0.0.1 25" work? Does Wireshark reveal anything about what's going on? Could a firewall be blocking the access?

---

<div class="post-metadata">

**Author:** ![Bob04](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@Bob04](https://discuss.elastic.co/u/Bob04)\
**Post date:** [July 6, 2017, 4:47pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/12 "2017-07-06T16:47:52Z")

</div>

It looks like everything should work.

I also tried to send email this way and I was able to receive it:

`mail -s "subject" recipient@email.com <email_body>`

And this way:

```
sendmail EMAILADDRESS
FROM: FROMADDRESS
SUBJECT: hello world
this is a test email
.

```

When I tried to send email via `sendmail` I got this errors:

```
11:56:31.514 [[main]>worker0] ERROR logstash.outputs.email - Something happen while delivering an email {:exception=>#<IOError: Cannot run program "/usr/sbin/sendmail" (in directory "/"): error=2, No such file or directory>}
11:56:31.590 [[main]>worker0] ERROR logstash.outputs.email - Something happen while delivering an email {:exception=>#<IOError: Cannot run program "/usr/sbin/sendmail" (in directory "/"): error=2, No such file or directory>}

```

It looks like it happened because I am running Logstash in Docker.

Though when I mounted local file `/usr/sbin/sendmail` by `-v /usr/sbin/sendmail:/usr/sbin/sendmail` I got another error:

```
/usr/share/logstash/vendor/bundle/jruby/1.9/gems/mail-2.6.4/lib/mail/network/delivery_methods/sendmail.rb:73 warning: unsupported popen option: err
/usr/share/logstash/vendor/bundle/jruby/1.9/gems/mail-2.6.4/lib/mail/network/delivery_methods/sendmail.rb:73 warning: unsupported popen option: err
12:29:35.742 [[main]>worker0] ERROR logstash.outputs.email - Something happen while delivering an email {:exception=>#<Errno::EPIPE: Broken pipe - Broken pipe>}
```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 6, 2017, 8:00pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/13 "2017-07-06T20:00:48Z")

</div>

> mail -s "subject" [recipient@email.com](mailto:recipient@email.com) \<email\_body\>

mail doesn't use SMTP.

> sendmail EMAILADDRESS

sendmail doesn't use SMTP.

> It looks like it happened because I am running Logstash in Docker.

That's crucial information! With containers running in bridge mode (the default), connections to localhost inside the container won't reach the host. You need to make sure you really connect to the host (e.g. by using its DNS name). Another option is to run the container in host network mode.

> Though when I mounted local file /usr/sbin/sendmail by -v /usr/sbin/sendmail:/usr/sbin/sendmail I got another error:

That'll never work. The sendmail binary needs access to various other files.

---

<div class="post-metadata">

**Author:** ![Bob04](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@Bob04](https://discuss.elastic.co/u/Bob04)\
**Post date:** [July 11, 2017, 3:11pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/14 "2017-07-11T15:11:12Z")

</div>

Thanks for clarification.

In my case, ELK containers are connected to each other with with `link`. Is there any way to connect to a local host from a container to be able to run `Sendmail` or `Postfix`?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 11, 2017, 5:52pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/15 "2017-07-11T17:52:54Z")

</div>

> In my case, ELK containers are connected to each other with with link. Is there any way to connect to a local host from a container to be able to run Sendmail or Postfix?

I don't think there's a way to connect to the loopback interface of the host if you're running a container in bridge mode. As I said, either connect to the non-loopback interface on the host (e.g. by using its DNS name) or run the container in host network mode.

---

<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:** [August 8, 2017, 5:53pm UTC](https://discuss.elastic.co/t/logstash-doesnt-send-any-emails/91967/16 "2017-08-08T17:53:12Z")

</div>

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