How to talk to IMAP server in Shell via OpenSSL

TerminalOpensslImap

Terminal Problem Overview


I want to send IMAP commands via Mac OS X Terminal to server and get response. I can connect to the server using this line:

openssl s_client -connect imap.gmail.com:993

And I can successfully login:

? LOGIN m.client2 passwordhere

But all other commands do not work, no response from server. I tried for instance this:

? LIST "" "*"
? SELECT INBOX

Terminal Solutions


Solution 1 - Terminal

Found an error by help of a friend:

openssl s_client -connect imap.gmail.com:993 -crlf

-crlf is critical

Solution 2 - Terminal

Try this, this should works for you (replace the first line by your

openssl s_client -connect imap.gmail.com:993 -crlf

command (mandatory -crlf) & type only the blue part) :

enter image description here

Solution 3 - Terminal

First thing first, is imap activated on your gmail account??? if you are able to login successfully that means ssl is working fine. whats the return code that you get for

>a1 LOGIN m.client2 passwordhere command.

have you tried the command

>a1 capability

try other alternative commands since not all IMAP servers implementa all the IMAP commands. I have faced this issue while I was creating the data migration tools for different vendors like gmail rediffmail yahoo...

Solution 4 - Terminal

A few more options to consider: You may be connecting to a server offering STARTTLS (esp. for IMAP on port 143) in which case you can tell openssl to proceed in negotiating this, you need to specify which protocol you're using (choose from pop3, imap, smtp, ftp); the -crlf option has been mentioned by others, and I also find the -showcerts option useful if I'm debugging an SSL/TLS configuration. So for example you might end up with,

 openssl s_client -showcerts -connect target.server.name.here:143 -starttls imap

More options with the relevant man page if you've got that available,

man s_client

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDenis KutlubaevView Question on Stackoverflow
Solution 1 - TerminalDenis KutlubaevView Answer on Stackoverflow
Solution 2 - TerminalGilles QuenotView Answer on Stackoverflow
Solution 3 - TerminalAnshulView Answer on Stackoverflow
Solution 4 - TerminalAndrew RichardsView Answer on Stackoverflow