# How can I check IMAP of a remote server in command line?



## samanka80 (Aug 13, 2013)

Hi guys,

I have this need, say I have an account on a remote server, for example Gmail. 

my username: gmail-test
password:  gmail-pass

Now I am on the FreeBSD 9.1 command line, I want to check and see if I can login to this Gmail account e.g imap.gmail.com port 993, using just the command line and fetch my mail. Is it possible and if yes, how?


----------



## SirDice (Aug 13, 2013)

Install and configure an email client like mail/mutt.


----------



## DutchDaemon (Aug 13, 2013)

What ^^ said. You can't do this manually. It involves SSL, hence encryption. You need an application that handles that layer for you.


----------



## SirDice (Aug 13, 2013)

I'm not 100% sure mutt supports IMAP though. I was actually looking for pine but it seems to have disappeared from the ports tree.


----------



## wblock@ (Aug 13, 2013)

mail/alpine is the latest version.  Never tried it for IMAP, though.


----------



## Abriel (Aug 13, 2013)

I am using mail/alpine with IMAP, if remember, you need only change

```
inbox-path={imap.hostname.net/SSL/novalidate-cert}INBOX
folder-collections=somemail {imap.hostname.net/ssl/novalidate-cert}[]
```
I did it a long time ago. Of course, you can delete novalidate-cert: https://www.cs.virginia.edu/~csadmin/wiki/index.php/Setting_up_Pine_(Alpine)_for_IMAP_Gmail


----------



## DutchDaemon (Aug 13, 2013)

Note that this is IMAP*S*!


----------



## segfault (Aug 13, 2013)

I use mail/offlineimap with mail/mutt. Seems to work nicely with my company's exchange server too.


----------



## schrodinger (Aug 13, 2013)

You can do a simple raw test from the CLI using OpenSSL.


```
$ openssl s_client -connect imap.gmail.com:993 
CONNECTED(00000003)
depth=1 C = US, O = Google Inc, CN = Google Internet Authority
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com
   i:/C=US/O=Google Inc/CN=Google Internet Authority
 1 s:/C=US/O=Google Inc/CN=Google Internet Authority
   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIDgDCCAumgAwIBAgIKVEsbtQABAACELjANBgkqhkiG9w0BAQUF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SM97W6MO6UiqmVvbMhwPBrktUVT/Q4cWskVf2MONrW3g0UtX47L1ocs/WZe
XdUTkjQ3EFCzxpw4joHefndfZHsEn0VrjZR49kzR9+1Me7Rz
-----END CERTIFICATE-----
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=imap.gmail.com
issuer=/C=US/O=Google Inc/CN=Google Internet Authority
---
No client certificate CA names sent
---
SSL handshake has read 2110 bytes and written 444 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-RC4-SHA
Server public key is 1024 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-RC4-SHA
    Session-ID: 86FBA9AF75E51767A4529C60E7079F85CDC4AE2FBB08BF699D7BCC72565D4843
    Session-ID-ctx: 
    Master-Key: DCF65077507D6CBFF00CA969AC260563D7C908EA9B42D3B68D04490AE194155727B2F432552FB62F284FFFC035175C0E
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 100800 (seconds)
    TLS session ticket:
    0000 - f2 bd 01 c1 93 f2 a4 ce-5a 97 64 bb 35 1f b9 4c   ........Z.d.5..L
    0010 - e6 ff 7a 55 b2 73 56 49-49 81 fe 25 8c 87 d1 67   ..zU.sVII..%...g
    0020 - cd e4 00 27 a6 ed ef 71-69 a0 2e 75 ed 5e 42 c6   ...'...qi..u.^B.
    0030 - a8 83 13 76 13 95 a9 9b-01 63 1e 28 94 c5 ba 99   ...v.....c.(....
    0040 - 58 37 8e 15 ed ea d4 1e-00 8a df c9 a3 ed 3d ed   X7............=.
    0050 - 55 3d 03 b8 22 38 f2 c3-4e 00 04 9f 53 ea e8 7f   U=.."8..N...S...
    0060 - 00 df 08 fc 2d 72 c0 2e-9e c6 e3 c5 f6 92 44 c0   ....-r........D.
    0070 - f5 31 37 75 40 3a 87 7a-83 c3 8b 34 e7 ca 10 6d   .17u@:.z...4...m
    0080 - 18 df c6 d6 ee 8d c8 9d-43 15 2e 2e 77 70 d6 c0   ........C...wp..
    0090 - 37 12 f7 fa                                       7...

    Start Time: 1376418483
    Timeout   : 300 (sec)
    Verify return code: 20 (unable to get local issuer certificate)
---
* OK Gimap ready for requests
a1 LOGIN gmail-test gmail-test
a1 NO [ALERT] Invalid credentials (Failure)
```


----------



## roddierod (Aug 13, 2013)

How about mail/fetchmail?


----------



## samanka80 (Aug 14, 2013)

Thank you all for your reply. I tested both mutt and fetchmail, fetchmail is really bendy, easy to configure and flexible in use.


----------



## fonz (Aug 14, 2013)

SirDice said:
			
		

> I'm not 100% sure mutt supports IMAP though.





			
				DutchDaemon said:
			
		

> Note that this is IMAP*S*!



Although I don't use it myself (I just ssh into the mailserver and use Mutt from there), but I'm pretty sure Mutt supports both IMAP and SSL.


----------

