# Imap connection to gmail closes connection

**URL:** <https://www.ruby-forum.com/t/imap-connection-to-gmail-closes-connection/238526>\
**Category:** NGINX\
**Created:** [January 15, 2014, 4:37pm UTC](https://www.ruby-forum.com/t/imap-connection-to-gmail-closes-connection/238526 "2014-01-15T16:37:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [January 15, 2014, 4:37pm UTC](https://www.ruby-forum.com/t/imap-connection-to-gmail-closes-connection/238526/1 "2014-01-15T16:37:53Z")

</div>

I am running nginx 1.1.19 on an Ubuntu 12.04.4 64but server.

I have nginx configured to enter on port 143 and go out to 127.0.0.1:143  
where it goes through stunnel to go to [imap.gmail.com:993](http://imap.gmail.com:993). If I talk  
directly to 127.0.0.1:143 (to stunnel) it works. If I talk to nginx, it  
authenticates, logs correct username, target IP and port, gets the  
Capability list and registers a successful login to the remote (gmail)  
imap  
server and then closes the connection immediately. The following is a  
transcript of the telnet session:

telnet nginx:143

- OK IMAP4 ready  
a1 LOGIN removed\_email\_address@domain.invalid password
- CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN  
X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH  
a1 OK removed\_email\_address@domain.invalid first\_name Last\_name authenticated (Success)  
Connection closed by foreign host.

My nginx error.log shows the following:  
_5 upstream sent invalid response: "_ CAPABILITY IMAP4rev1 UNSELECT IDLE  
NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE  
ENABLE  
MOVE CONDSTORE ESEARCH  
a1 OK removed\_email\_address@domain.invalid Test User authenticated (Success)" while reading  
response from upstream,…

It appears to not like google’s CAPABILITY line. Is it too long? Any  
suggestions?

Other connections through nginx/stunnel to exchange work just fine.

Posted at Nginx Forum:

> **[imap connection to gmail closes connection](https://forum.nginx.org/read.php?2,246483,246483#msg-246483)**
>
> I am running nginx 1.1.19 on an Ubuntu 12.04.4 64but server. I have nginx configured to enter on port 143 and go out to 127.0.0.1:143 where it goes through stunnel to go to imap.gmail.com:993. If I talk directly to 127.0.0.1:143 (to stunnel) it...

---

<div class="post-metadata">

**Author:** ![bidwell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bidwell](https://www.ruby-forum.com/u/bidwell)\
**Post date:** [January 15, 2014, 5:52pm UTC](https://www.ruby-forum.com/t/imap-connection-to-gmail-closes-connection/238526/2 "2014-01-15T17:52:23Z")

</div>

Hello!

On Wed, Jan 15, 2014 at 10:37:29AM -0500, bidwell wrote:

> telnet nginx:143  
> MOVE CONDSTORE ESEARCH  
> a1 OK [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) Test User authenticated (Success)" while reading  
> response from upstream,…
> 
> It appears to not like google’s CAPABILITY line. Is it too long? Any  
> suggestions?
> 
> Other connections through nginx/stunnel to exchange work just fine.

The problem is that nginx doesn’t expect multiple responses to the  
LOGIN command.

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![bidwell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bidwell](https://www.ruby-forum.com/u/bidwell)\
**Post date:** [January 16, 2014, 12:04pm UTC](https://www.ruby-forum.com/t/imap-connection-to-gmail-closes-connection/238526/3 "2014-01-16T12:04:21Z")

</div>

Hello!

On Wed, Jan 15, 2014 at 11:28:18AM -0600, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > authenticates, logs correct username, target IP and port, gets the  
> > > Connection closed by foreign host.
> 
> Hi Maxim,
> 
> I tried posting to the list but it never came through.

You have to be subscribed to the list to post to it, see  
[http://nginx.org/en/support.html](http://nginx.org/en/support.html).

> Here is the patch  
> we found in the nginx archives to address this problem.

[…]

Thanks, it looks like the patch from this message:

> **[(resending) bug in ngx\_mail\_proxy\_read\_response](http://mailman.nginx.org/pipermail/nginx/2007-November/002269.html)**

Posting the link on the list in case it will be usable for  
someone.

Unfortunately, the patch is more like a quick-and-dirty  
workaround, and needs more work before it can be committed.

–  
Maxim D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![bidwell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bidwell](https://www.ruby-forum.com/u/bidwell)\
**Post date:** [January 15, 2014, 6:03pm UTC](https://www.ruby-forum.com/t/imap-connection-to-gmail-closes-connection/238526/4 "2014-01-15T18:03:17Z")

</div>

Is there a work around? A google setting maybe? Is anyone else using  
nginx  
to map to [imap.gmail.com](http://imap.gmail.com)? How do they get it working?

Posted at Nginx Forum:

> **[Re: imap connection to gmail closes connection](https://forum.nginx.org/read.php?2,246483,246488#msg-246488)**
>
> I am running nginx 1.1.19 on an Ubuntu 12.04.4 64but server. I have nginx configured to enter on port 143 and go out to 127.0.0.1:143 where it goes through stunnel to go to imap.gmail.com:993. If I talk directly to 127.0.0.1:143 (to stunnel) it...
