diff --git a/Changelog.draft.rst b/Changelog.draft.rst
index 44b4a87..8addd4f 100644
--- a/Changelog.draft.rst
+++ b/Changelog.draft.rst
@@ -23,6 +23,8 @@ Changes
 Bug Fixes
 ---------
 
+* Allow SSL connections to send keep-alive messages.
+
 
 Pending for the next major release
 ==================================
diff --git a/offlineimap/imaplibutil.py b/offlineimap/imaplibutil.py
index 69d3983..6752328 100644
--- a/offlineimap/imaplibutil.py
+++ b/offlineimap/imaplibutil.py
@@ -110,6 +110,10 @@ class WrappedIMAP4_SSL(IMAP4_SSL):
             # FIXME
             raise socket.error(last_error)
 
+        # Allow sending of keep-alive message seems to prevent some servers
+        # from closing SSL on us leading to deadlocks
+        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
+
         #connected to socket, now wrap it in SSL
         try:
             if self._cacertfile:
