58

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
Mansueli
  • 6,223
  • 8
  • 33
  • 57
Denis Kutlubaev
  • 15,320
  • 6
  • 84
  • 70
  • 3
    Mac OS X Terminal is not aka Bash. Terminal and shell are not the same! – johnsyweb Feb 19 '13 at 14:11
  • This command sequence (after select inbox) is useful: `4 SEARCH SENTSINCE "14-Oct-2018"`, then pick a number and do `5 FETCH XXXX (FLAGS BODY[HEADER.FIELDS (DATE FROM SUBJECT)] BODY[TEXT])` to see the full email. – Florian Oct 16 '18 at 20:21

4 Answers4

80

Found an error by help of a friend:

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

-crlf is critical

Denis Kutlubaev
  • 15,320
  • 6
  • 84
  • 70
  • I came across this looking for a reason why the server was ignoring all of my commands. It would time out after a period of inactivity, but as long as I kept typing the connection would stay open (but it never responded). – Jeremy Figgins Jan 30 '19 at 01:01
  • Gmail seems to have rolled out an update over the past few days which now requires this option. It's still not necessary for Cyrus IMAPd. (I had connected this way regularly for all my Gmail access without the `-crlf` for many years, but starting a few days ago some connections would hang, and today they were all hanging.) – Greg A. Woods May 03 '19 at 19:34
  • 2
    Apparently, the cmdline syntax has tightened since this posting: New syntax is: `openssl s_client -crlf localhost:993`. Note that the `-crlf` option occurs before the hostname. – John Greene May 07 '20 at 21:27
24

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

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
5

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...

Anshul
  • 1,416
  • 1
  • 16
  • 42
5

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
Andrew Richards
  • 1,392
  • 11
  • 18