Accessing gmail from the commandline

5,138 views
Skip to first unread message

shadebug

unread,
Dec 14, 2011, 9:00:00 PM12/14/11
to Gmail-Users
I spend my days setting people's email clients up and it occurred to
me, on a whim, that it might be useful if I could telnet into their
servers and check to see what's actually there when something's up
(for instance, I recently set up a customer's account, not gmail, and
of her hundreds of mailboxes the only one it retrieved was a single
subsubsubfolder despite her webmail client showing me all sorts of
wonderful stuff). I soon discovered that this is actually pretty easy
and was quickly able to log into and peruse email using telnet for my
personal domain and ssl for yahoo's secure servers. When I tried it on
gmail, however, it was happy to login (that is to say authenticate,
not just open the connection) and then nothing else worked. Even the
logout command did nothing.

So the question here is, why?

Marko Vukovic

unread,
Dec 15, 2011, 9:56:02 AM12/15/11
to gmail...@googlegroups.com
I assume you are using Telnet over stunnel or the like and attempting to talk IMAP.

Using OpenSSL I see the same symptom as you, can login but no response to commands. Weird!
$ openssl s_client -connect imap.gmail.com:993
.
.
.
* OK Gimap ready for requests from xx.xx.xx.xx e4if4030674wiv.185
01 login marko....@gmail.com **********
* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE
01 OK marko....@gmail.com Marko Vukovic authenticated (Success)
02 logout

^C
$

POP3 works fine though...


--
You received this message because you are subscribed to the Google Groups "Gmail-Users" group.
To post to this group, send email to gmail...@googlegroups.com.
To unsubscribe from this group, send email to gmail-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gmail-users?hl=en.




--
Marko

shadebug

unread,
Dec 15, 2011, 4:19:11 PM12/15/11
to Gmail-Users
You think some sort of secure telnet session would do it better than
straight openssl? How would that even work and would I need to install
anything (telnet and openssl are things I can expect to find within
metres of me wherever I am)?

It's all very well and good that pop3 works but I'm not going to
subject anybody to that.

EdD

On Dec 15, 2:56 pm, Marko Vukovic <marko.vuko...@gmail.com> wrote:
> I assume you are using Telnet over stunnel or the like and attempting to
> talk IMAP.
>
> Using OpenSSL I see the same symptom as you, can login but no response to
> commands. Weird!
> $ openssl s_client -connect imap.gmail.com:993
> .
> .
> .
> * OK Gimap ready for requests from xx.xx.xx.xx e4if4030674wiv.185

> 01 login marko.vuko...@gmail.com **********


> * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN
> X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE

> 01 OK marko.vuko...@gmail.com Marko Vukovic authenticated (Success)

Marko Vukovic

unread,
Dec 16, 2011, 7:22:07 AM12/16/11
to gmail...@googlegroups.com
Hi Ed

I'm not sure what you mean by 'secure telnet'. Whether you use telnet via stunnel or OpenSSL, you need something that does the SSL handshake. I find OpenSSL c_client to be the simplest method to connect to an IMAPS server.

If you wouldn't want to subject anybody to POP3 via command line then why would you for IMAP, the protocol is by far more tedious to type in by hand. Why go through all this in any case? Surely if you have the login credentials the web interface is easiest? I would think you would have access to a web browser much easier than Telnet, Stunnel or OpenSSL s_client.

shadebug

unread,
Dec 17, 2011, 3:35:48 AM12/17/11
to Gmail-Users
I'm not planning to have customers use the CLI, I just want to use it
to determine if there is an IMAP server at an address and what
mailboxes it has access to. I don't ever expect gmail to be an issue
for me but if gmail has this issue then other servers might too so I
would like to know what it means and how to work round it.

EdD

Marko Vukovic

unread,
Dec 17, 2011, 8:04:57 AM12/17/11
to gmail...@googlegroups.com
What CLI? All you are doing is talking IMAP. This is not a CLI. There is no 'issue'. If I use an IMAP client, ie. Mail on my iPhone or Thunderbird, it works fine. 
My guess it that it's probably expecting a line feed.

What mailboxes it has access to? Well... the one you authenticated with!

In any case, this topic really has nothing to do with Gmail. 

shadebug

unread,
Dec 17, 2011, 7:07:52 PM12/17/11
to Gmail-Users
But if my IMAP client isn't working then I need to know why it isn't
working, is it a problem with the client or the server? The reason I'm
after a CLI method such as telnet or openssl is that it will be
readily available to me without having to install new software
anywhere. On all my addresses (that is, addresses I know the username
and password for) openssl works fine for logging int and browsing
mailbox structure and messages. That being said, it's entirely likely
that if GMail behaves in this strange manner then there may be many
others IMAP servers that do the same, in which case I would like to
know why and if anything can be done to access the mailbox structure
and messages in a more direct way than just using a mail client.

Two situations where this would be useful
Alice has her company email set up as separate mailboxes within one
overarching mailbox. Being able to see the structure would allow me to
work out what IMAP path to use to set up her email client properly.
Bob has an exotic mail set up that is meant to be accessed by webmail
but also has IMAP capability. When accessed through IMAP only one
folder appears whereas the webmail client shows many. Accessing the
mailbox structure directly would let me work out if it is a problem
with the client reading the information wrong or if the webmail is
accessing the mailbox from a different source.

If you know a better way round the issue I would be happy to hear it.

EdD

Marko Vukovic

unread,
Dec 18, 2011, 11:15:05 AM12/18/11
to gmail...@googlegroups.com
Again Ed, there is no issue. IMAP to Gmail works just fine using an IMAP capable client. I also don't see what your examples have to do with Gmail.

If you'd read my previous post, I mentioned I suspected Gimap was probably expecting a line feed. If you want to talk IMAP, then you should at least consult the RFC. If you'd done that you'd have noticed this paragraph:

2.2. Commands and Responses

An IMAP4rev1 connection consists of the establishment of a client/server network connection, an initial greeting from the server, and client/server interactions. These client/server interactions consist of a client command, server data, and a server completion result response. All interactions transmitted by client and server are in the form of lines, that is, strings that end with a CRLF. The protocol receiver of an IMAP4rev1 client or server is either reading a line, or is reading a sequence of octets with a known count followed by a line.


If you had then RTFM for s_client, you would have found the -crlf option:

-crlf
           this option translated a line feed from the terminal into CR+LF as required by some servers.

So...

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

shadebug

unread,
Dec 19, 2011, 5:13:06 AM12/19/11
to Gmail-Users
Thank you, that's the answer I was after and works beautifully.

EdD

On Dec 18, 4:15 pm, Marko Vukovic <marko.vuko...@gmail.com> wrote:
> Again Ed, there is no issue. IMAP to Gmail works just fine using an IMAP
> capable client. I also don't see what your examples have to do with Gmail.
>
> If you'd read my previous post, I mentioned I suspected Gimap was probably
> expecting a line feed. If you want to talk IMAP, then you should at least

> consult the RFC <http://tools.ietf.org/html/rfc3501>. If you'd done that

pdiddy

unread,
Jul 24, 2013, 10:13:52 AM7/24/13
to gmail...@googlegroups.com
I'm trying to access gmail from RHEL 6 with below command and getting "unknown command" error, please let me know how to fix it...

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

* OK Gimap ready for requests from 192.81.68.110 ip4if329360vdb.60
login mye...@gmail.com mypass
login BAD Unknown command ip4if329360vdb.60
-----------

Marko Vukovic

unread,
Jul 25, 2013, 5:29:16 AM7/25/13
to gmail-users

On Wed, Jul 24, 2013 at 4:13 PM, pdiddy <dpa...@gmail.com> wrote:
I'm trying to access gmail from RHEL 6 with below command and getting "unknown command" error, please let me know how to fix it...

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

* OK Gimap ready for requests from 192.81.68.110 ip4if329360vdb.60
login mye...@gmail.com mypass
login BAD Unknown command ip4if329360vdb.60

You have no tag in front of your command. 

If you don't know what you're doing here rather don't try, you risk having your account blocked for suspicious login attempts so do this at your own peril.


--
Marko
Reply all
Reply to author
Forward
0 new messages