Re: Timeout when trying to append a big/long message into a mailbox

Nicolas Le Manchet

The interesting thing here is that the timeout occurs on write. It looks like the TCP buffers from you to gmail are full and gmail is not consuming bytes fast enough.

There are a few things you can try to debug:

- The traceback shows that you are using `backports.ssl`, did you try running this code from IMAPClient master using the `ssl` module?
- Did you try raising the timeout to an extremely high value to see if it will eventually work?

By the way, I think we could separate the connect and read/write timeout in IMAPClient, like what `requests` does. Usually you want a short connect timeout but long read/write timeout to accommodate slow servers.

Le 14/09/2017 16:41, maxime.lorant@... a écrit :
I discovered a weird bug, regarding *some* Gmail IMAP accounts...
For some reason, I am trying to append a message I just sent using the
SMTP server (and delete the one automatically set by
It works fine for fairly simple message, but if timeouts after a
certain message size. I have not been able to determine the size, but
as long as you have an attachment, the timeout is almost always
trigerred... It does happen on several Gmail accounts, so it does not
seem an isolated case...
Did anyone encounter this? The problem does not come from imapclient
but maybe someone has a clue about this... I can't reproduce it on
other IMAP servers.

imap = IMAPClient('')
# Assume a oauth2_login call here
imap.append('INBOX', 'Subject: Test\r\n\r\n%s' % ('Test test' *
100)) # Small message body, seems OK (appears in my mailbox
b'[APPENDUID 634670718 26357] (Success)'

imap.append('INBOX', 'Subject: Test\r\n\r\n%s' % ('Test test' *
Traceback (most recent call last):
File ".../lib/python3.5/site-packages/backports/ssl/", line
201, in _safe_ssl_call
return getattr(sock, call)(*args, **kwargs)
File ".../lib/python3.5/site-packages/OpenSSL/", line 1540, in
self._raise_ssl_error(self._ssl, result)
File ".../lib/python3.5/site-packages/OpenSSL/", line 1433, in
raise WantWriteError()
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".../modules/python3.5.2/lib/python3.5/", line 987,
in _command
File ".../lib/python3.5/site-packages/imapclient/", line 171,
in send
sent = self.sock.send(data)
File ".../lib/python3.5/site-packages/backports/ssl/", line
281, in send
return _safe_ssl_call(False, self._conn, 'send', data, flags)
File ".../lib/python3.5/site-packages/backports/ssl/", line
209, in _safe_ssl_call
raise socket.timeout()
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".../python3.5.2/lib/python3.5/", line 91, in runcode
exec(code, self.locals)
File "", line 1, in
File ".../lib/python3.5/site-packages/imapclient/",
line 1007, in append
File ".../lib/python3.5/site-packages/imapclient/",
line 1180, in _command_and_check
typ, data = meth(*args)
File ".../python3.5.2/lib/python3.5/", line 387, in append
return self._simple_command(name, mailbox, flags, date_time)
File ".../python3.5.2/lib/python3.5/", line 1180, in
return self._command_complete(name, self._command(name, *args))
File ".../python3.5.2/lib/python3.5/", line 990, in
raise self.abort('socket error: %s' % val)
imaplib.abort: socket error:

Join to automatically receive all group messages.