# Imap input filter - connection refused

**URL:** <https://discuss.elastic.co/t/imap-input-filter-connection-refused/2162>\
**Category:** Logstash\
**Created:** [June 8, 2015, 8:36pm UTC](https://discuss.elastic.co/t/imap-input-filter-connection-refused/2162 "2015-06-08T20:36:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vilas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vilas/32/613_2.png) [@vilas](https://discuss.elastic.co/u/vilas)\
**Post date:** [June 8, 2015, 8:36pm UTC](https://discuss.elastic.co/t/imap-input-filter-connection-refused/2162/1 "2015-06-08T20:36:14Z")

</div>

Hi,

I am trying to use imap input filter. Using gmail account for testing purposes.  
**Config File**

```auto
input {
	imap {
			host => "imap.gmail.com"
			user => "someuser@gmail.com"
			password => "somepassword"
			port => 993
			type => "imap"
	}
}

output {
	stdout { codec => rubydebug }
}

```

**Output Error**

```auto
←[31mA plugin had an unrecoverable error. Will restart this plugin.
  Plugin: <LogStash::Inputs::IMAP host=>"imap.gmail.com", user=>"someuser@gmail.com", type=>"imap", content_type=>"text/plain">
  Error: Connection refused - Connection refused {:level=>:error}←[0m
←[31mA plugin had an unrecoverable error. Will restart this plugin.
  Plugin: <LogStash::Inputs::IMAP host=>"imap.gmail.com", user=>"someuser@gmail.com", type=>"imap", content_type=>"text/plain">
  Error: Connection refused - Connection refused {:level=>:error}←[0m
IOError: closed stream
        close at org/jruby/RubyIO.java:2096
     teardown at C:/Tools/logstash-1.4.2/lib/logstash/inputs/imap.rb:145
  inputworker at C:/Tools/logstash-1.4.2/lib/logstash/pipeline.rb:184
  start_input at C:/Tools/logstash-1.4.2/lib/logstash/pipeline.rb:157

```

**Please suggest what could be the issue here**

Thanks

---

<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:** [June 8, 2015, 8:47pm UTC](https://discuss.elastic.co/t/imap-input-filter-connection-refused/2162/2 "2015-06-08T20:47:58Z")

</div>

[imap.gmail.com:993](http://imap.gmail.com:993) should be available for connections. I'm able to connect. What if you try yourself with telnet (`telnet imap.gmail.com 993`)? Until that works there's no point trying with Logstash.

---

<div class="post-metadata">

**Author:** ![vilas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vilas/32/613_2.png) [@vilas](https://discuss.elastic.co/u/vilas)\
**Post date:** [June 8, 2015, 10:07pm UTC](https://discuss.elastic.co/t/imap-input-filter-connection-refused/2162/3 "2015-06-08T22:07:53Z")

</div>

Thanks for your reply @magnusbaeck  
I tried the telnet and it is not connecting. I am currently trying to understand why.

So, I am using another email domain credentials. Now I am able to see some email being received.  
But I have problem with character encoding.

```auto
[33mReceived an event that has a different character encoding than you configured.

```

My email server is microsoft exchange server.

Is it related to content-type? Please suggest.

Thanks.

---

<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:** [June 8, 2015, 10:13pm UTC](https://discuss.elastic.co/t/imap-input-filter-connection-refused/2162/4 "2015-06-08T22:13:09Z")

</div>

You may have to set a different codec (although I think the imap input should do this automatically based on each message's character set):

```
input {
  imap {
    ...
    codec => plain {
      charset => "some-charset-that-matches-your-data"
    }
  }
}

```

See the [plain codec documentation](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-plain.html) for a list of valid character sets.

---

<div class="post-metadata">

**Author:** ![vilas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vilas/32/613_2.png) [@vilas](https://discuss.elastic.co/u/vilas)\
**Post date:** [June 8, 2015, 10:40pm UTC](https://discuss.elastic.co/t/imap-input-filter-connection-refused/2162/5 "2015-06-08T22:40:51Z")

</div>

It tried this:

```auto
codec => plain {
	charset => "Windows-1255"
}

```

I got this charset from email header.  
Logstash is crashing with this error:

```auto
 Error: undefined method `encode' for nil:NilClass {:level=>:error}←[0m

```

---

<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, 5:38am UTC](https://discuss.elastic.co/t/imap-input-filter-connection-refused/2162/6 "2017-07-06T05:38:06Z")

</div>


