To retrieve inforamtion about message structure, use the ImapListFields.MessageStructure parameter in the GetMessageInfo or GetMessageList methods.
Following example prints requested information:
C#
// connect and login
Imap imap = new Imap();
imap.Connect(...);
imap.Login(...);
imap.SelectFolder("INBOX");
// retrieve information of emails envelope and structure
ImapMessageCollection col =
imap.GetMessageList(ImapListFields.Envelope | ImapListFields.MessageStructure);
// print the information
foreach (ImapMessageInfo item in col)
{
Console.WriteLine("{0}: {1}", item.SequenceNumber, item.Subject);
foreach (ImapMessagePart part in item.GetParts())
{
if (part.Kind == ImapMessagePartKind.Attachment)
{
Console.WriteLine(" {0} [{1} B]", part.FileName, part.Length);
}
}
}
VB.NET
''# connect and login
Dim imap = New Imap()
imap.Connect(...)
imap.Login(...)
imap.SelectFolder("INBOX")
''# retrieve information of emails envelope and structure
Dim col = imap.GetMessageList(ImapListFields.Envelope Or ImapListFields.MessageStructure)
''# print the information
For Each item As ImapMessageInfo In col
Console.WriteLine("{0}: {1}", item.SequenceNumber, item.Subject)
For Each part In item.GetParts()
If part.Kind = ImapMessagePartKind.Attachment Then
Console.WriteLine(" {0} [{1} B]", part.FileName, part.Length)
End If
Next part
Next item
Please note the ImapListFields flags are combined together with the OR binary operator (not AND) as shown in the imap.GetMessageList method call.
answered
31 May '11, 15:18
Rebex KB ♦♦
258●5●19
accept rate:
63%