General Info/Mail Server CLI/IMAP
Mail Server CLI | POP | IMAP | ESMTP
Contents |
IMAP Overview
- IMAP
- Internet Message Access Protocol : Application layer internet standard protocol that uses TCP/IP. Currently version 4 revision 1 is the standard.
Testing from a command line interface provides a virtually guaranteed way of confirming basic requirements for a successfully connection. Observations and responses observed come directly from the mail server rather than trying to interpret an application's translation of the scenario. Keep in mind that testing from a command line is generally in plain text, which is insecure, unless you use a connect application such as openssl
While much easier to test from a Linux terminal, it is possible to test from a windows command prompt, however, keep in mind that Windows does not allow you to backspace or delete any mistakes that you make. While unconfirmed, based on behavior it appears that Windows actively submits every keystroke to the mail server rather than waiting for "return".
All IMAP commands passed to the server must be proceeded by a character and a space. The character can be pretty much be anything.
. login username password
IMAP Commands
LOGIN
- Command used for logging into the desired mailbox
. login username password . OK LOGIN completed.
CAPABILITY
- Provides a listing of what commands the server supports. Generally it lists what version of IMAP is supported, then any additional commands.
. CAPABILITY * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN CHILDREN IDLE NAMESPACE LITERAL+ . OK CAPABILITY completed.
LIST
- Provides a listing of folders within the mailbox. You can specify a specific folder, or you can use a wildcard, like the example below. Blank double quotes would represent the parent directory, however, you cannot use this on its own and it must be combined with a wildcard.
. list "" "*" * LIST (\HasNoChildren) "/" Calendar * LIST (\HasNoChildren) "/" Contacts * LIST (\HasNoChildren) "/" "Conversation History"
. list "INBOX" "*" * LIST (\Marked \HasChildren) "/" INBOX * LIST (\HasNoChildren) "/" INBOX/Applications * LIST (\HasNoChildren) "/" "INBOX/Client Notifications"
SELECT
- Selects the desired folder. You must first select the folder before you can view or modify messages within it.
. select Drafts * 4 EXISTS * 4 RECENT * FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent) * OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags * OK [UNSEEN 2] Is the first unseen message * OK [UIDVALIDITY 3516] UIDVALIDITY value * OK [UIDNEXT 2551] The next unique identifier value . OK [READ-WRITE] SELECT completed.
FETCH
Fetch displays message information, either in whole or just certain parts, however, you must have selected a folder first. I will only cover the basic options for fetch, if you want to learn more, visit Google. You must specify the command, followed by the message number, then the fetch option.
- FULL
- fetches all of the internet headers and message body.
. fetch 4 full * 4 FETCH (FLAGS (\Draft) INTERNALDATE "25-Jul-2012 17:50:30 -0400" RFC822.SIZE 34269 ENVELOPE (NIL NIL NIL NIL NIL NIL NIL NIL NIL " <3D4A65565EFB3D4B9A541F98D0DA17D714DE9791@S1P5DAG2C.EXCHPROD.USA.NET>") BODY (("text" "html" ("charset" "us-ascii") NIL NIL "quoted-printable" 28175 545)("image" "jpeg" ("name" "image001.jpg") "<[email protected]>" "image001.jpg" "base64" 5778) "related")) . OK FETCH completed.
- RFC822.HEADER
- fetches just the header information of the message
. fetch 309 rfc822.header * 309 FETCH (RFC822.HEADER {2498} Received: from gwsin07.mbox.net [165.212.64.38] by cmsmail03.cms.usa.net via mtad (C8.MAIN.3.82G) with ESMTP id 764RHEPn11280M03; Sat, 31 Aug 2013 15:39:52 -0000 Return-Path: <[email protected]> Received: from gwsin07.mbox.net (gwsin.mbox.net [165.212.65.100]) by gwsin07.mbox.net (Postfix) with ESMTP id 3cS1vr3nBfzfhnrQ for <[email protected]>; Sat, 31 Aug 2013 15:39:52 +0000 (UTC) X-USANET-Received: from emd2.mbox.net [165.212.64.9] by gwsin07.mbox.net via mtad (C8.MAIN.3.82G) with ESMTP id 335RHEPnt1248Ms7; Sat, 31 Aug 2013 15:39:44 -0000 X-USANET-Routed: 10 gwsin-externalarchive C:gwsarchive:625 [email protected] X-USANET-Routed: 1 gwsin-bmcheck Q:bmcheck X-USANET-Routed: 10 gwsin-externalarchive C:gwsarchive:625 [email protected] X-USANET-Routed: 5 gwsin-gwsd Q:gwsd X-USANET-Routed: 2 gwsin-vs Q:bmrelayvs X-USANET-Routed: 100 IN-RELAY R:gwsin:650 X-USANET-GWS2-Tenant: farmersagent.com X-USANET-GWS2-Tagid: FI03 Received: from em-sj-82.mktomail.com [199.15.215.82] by emd2.mbox.net via smtad (C8.MAIN.3.90S) with ESMTP id XID703RHEPnt3527Xd2; Sat, 31 Aug 2013 15:39:45 -0000 X-USANET-Source: 199.15.215.82 IN [email protected] em-sj-82.mktomail.com X-USANET-MsgId: XID703RHEPnt3527Xd2 X-USANET-ApprovedSender: UNK X-MSFBL: aWxhdGhyb3BAZmFybWVyc2FnZW50LmNvbUBkdnAtMTk5LTE1LTIxNS04MkBiZy1z ai0wMUA1ODQtSEtWLTkwMDo1NDU6MTE4MjoyMzY0OjA6MTI5OTo3Ojc0MTI2Mw== Received: from [10.0.8.1] ([10.0.8.1:50392] helo=sjmas01.marketo.org) by sjmta03.marketo.org (envelope-from <[email protected]>) (ecelerity 3.5.0.35861 r(Momo-dev:tip)) with ESMTP id 28/32-06769-14E02225; Sat, 31 Aug 2013 10:39:45 -0500 Date: Sat, 31 Aug 2013 10:39:45 -0500 (CDT) From: National Association of Professional Women <[email protected]> Reply-To: [email protected] To: [email protected] Message-ID: <184676378.25376245.1377963585053.JavaMail.root@bg-sj-01> Subject: You're Invited: Join us at the Inc. Women's Summit and save! MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_25376236_472772387.1377963585045" X-Report-Abuse: Please report abuse here: http://www.marketo.com/policy breadcrumbId: ID-sjmas01-marketo-org-41295-1377720176785-0-64443348 X-MarketoID: 584-HKV-900:545:1182:2364:0:1299:7:741263 X-Mailfrom: [email protected] X-Binding: bg-sj-01 ) . OK FETCH completed
- RFC822
- fetches pretty much everything in the message
. fetch 4 rfc822 * 4 FETCH (RFC822 {34941} Subject: Thread-Index: AQHNarFoJpF7uLMAEkGPm8GPw83Wvw== Message-ID: <3D4A65565EFB3D4B9A541F98D0DA17D714DE9791@S1P5DAG2C.EXCHPROD.USA.NET> Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: Content-Type: multipart/related; boundary="_002_3D4A65565EFB3D4B9A541F98D0DA17D714DE9791S1P5DAG2CEXCHPR_"; type="text/html" MIME-Version: 1.0 --_002_3D4A65565EFB3D4B9A541F98D0DA17D714DE9791S1P5DAG2CEXCHPR_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr= osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" = xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:= //www.w3.org/TR/REC-html40"> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dus-ascii"= > <o:shapelayout v:ext=3D"edit"> <o:idmap v:ext=3D"edit" data=3D"1" /> </o:shapelayout></xml><![endif]--> </head> <body lang=3D"EN-US" link=3D"blue" vlink=3D"purple" style=3D"tab-interval:.= 5in"> Content-ID: <[email protected]> Content-Transfer-Encoding: base64 /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcG BwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwM DAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAA2AMgDASIA 2Q== --_002_3D4A65565EFB3D4B9A541F98D0DA17D714DE9791S1P5DAG2CEXCHPR_-- FLAGS (\Seen \Draft)) . OK FETCH completed.
- FLAGS
- fetches what flags have been set for the message. Flags define everything from whether or not you can see the message, what folder it is organized under, and if it needs to be deleted. This is why you commonly see "Purge" options in email clients, like Outlook, when you have configured an IMAP account. When you delete a message, it only adds the delete flag to the message, but does not delete it. You then must close your session for the new flag options to be applied.
. fetch 4 flags * 4 FETCH (FLAGS (\Seen \Draft)) . OK FETCH completed.
LOGOUT
- Does the obvious, logs you out.
. logout * BYE Microsoft Exchange Server 2010 IMAP4 server signing off. . OK LOGOUT completed.
Full Session Example
Franks-MacBook-Pro:~ fvazquez$ telnet exchange.postoffice.net 143 Trying 165.212.120.200... Connected to exchange.postoffice.net. Escape character is '^]'. * OK The Microsoft Exchange IMAP4 service is ready. . login username password . OK LOGIN completed. . CAPABILITY * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN CHILDREN IDLE NAMESPACE LITERAL+ . OK CAPABILITY completed. . list "" "*" * LIST (\HasNoChildren) "/" Calendar * LIST (\HasNoChildren) "/" Contacts * LIST (\HasNoChildren) "/" "Conversation History" . select Drafts * 4 EXISTS * 4 RECENT * FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent) * OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags * OK [UNSEEN 2] Is the first unseen message * OK [UIDVALIDITY 3516] UIDVALIDITY value * OK [UIDNEXT 2551] The next unique identifier value . OK [READ-WRITE] SELECT completed. . fetch 4 full * 4 FETCH (FLAGS (\Draft) INTERNALDATE "25-Jul-2012 17:50:30 -0400" RFC822.SIZE 34269 ENVELOPE (NIL NIL NIL NIL NIL NIL NIL NIL NIL " <3D4A65565EFB3D4B9A541F98D0DA17D714DE9791@S1P5DAG2C.EXCHPROD.USA.NET>") BODY (("text" "html" ("charset" "us-ascii") NIL NIL "quoted-printable" 28175 545)("image" "jpeg" ("name" "image001.jpg") "<[email protected]>" "image001.jpg" "base64" 5778) "related")) . OK FETCH completed. . fetch 4 flags * 4 FETCH (FLAGS (\Seen \Draft)) . OK FETCH completed. . logout * BYE Microsoft Exchange Server 2010 IMAP4 server signing off. . OK LOGOUT completed.