The following example demonstrates using aspNetIMAP to download a message as text.
There are two numbering systems to reference messages in the mail folder. Messages can be referenced by their ordinal position (i.e. 1, 2, 3, 4) , or by a unique identifier (UID). To convert an Ordinal message set to a UniqueId message set, check out MessageClient.ToUniqueId().
Multiple message numbers can be separated by commas or can be designated with a '*', which refers to the highest message number in the mail folder. A pair of numbers, separated by a ':', indicates a contiguous set of messages ranging from the first message number to the second. These ranges of message numbers are called 'message sets'. Message numbers, referenced by their ordinal index, are always ascending and always contiguous.
As an example, here are some message sets, and the respective messages they represent. All of the numbers used in this example, reference the messages by their ordinal index. This example also assumes there are 7 messages in the mail folder.
| MessageSet | Actual Message Numbers |
| 1 | 1 |
| 2, 5 | 2 5 |
| 1:* | 1 2 3 4 5 6 7 |
| 5:* | 5 6 7 |
| 1,2,5,7 | 1 2 5 7 |
| 2:5 | 2 3 4 5 |
| 1,3:5,7 | 1 3 4 5 7 |
| 1:3, 5:7 | 1 2 3 5 6 7 |
| 1,3:5,6:* | 1 3 4 5 6 7 |
These properly formatted message sets can be used when various
aspNetIMAP methods accept the messageSet parameter. Although this
example uses
Ordinal Indexes, the same technique (using commas ',' and asterisks '*' ) can be used with UID's (Unique Identifiers).
[C#]
IMAP4 imap = new IMAP4( "127.0.0.1", "dave@blah.com", "test" ); imap.Login(); //fetch the first message of the inbox MailFolder mf = imap.SelectInbox(); string text = mf.FetchClient.MessageAsText( 1, IndexType.Ordinal ); Console.WriteLine( text ); imap.Disconnect(); Console.WriteLine( "Done" ); Console.ReadLine();
[VB.NET]
Dim imap As New IMAP4("127.0.0.1", "dave@blah.com", "test") imap.Login() 'fetch the first message of the inbox Dim mf As MailFolder = imap.SelectInbox() Dim [text] As String = mf.FetchClient.MessageAsText(1, IndexType.Ordinal) Console.WriteLine([text]) imap.Disconnect() Console.WriteLine("Done") Console.ReadLine()