The following example demonstrates using aspNetIMAP to list out the
attachments found in a given message.
[C#]
IMAP4 imap = new IMAP4( "127.0.0.1" ); imap.Username = "dave@blah.com"; imap.Password = "test"; imap.Logger = new IMAPLog( "c:\\imap.log" ); imap.Login(); MailFolder mf = imap.SelectInbox(); //grab the BodyStructure of the newest message int count = mf.MessageCount; BodyStructure bs = mf.FetchClient.BodyStructure( count, IndexType.Ordinal ); BodyStructureAttachment[] attachments = bs.Attachments(); foreach(BodyStructureAttachment bsa in attachments ) { //write out the name and the id Console.WriteLine( "{0}:{1}", bsa.BodyStructureId, bsa.Name ); } Console.WriteLine( "Done" ); Console.ReadLine();
[VB.NET]
Dim imap As New IMAP4("127.0.0.1") imap.Username = "dave@blah.com" imap.Password = "test" imap.Logger = New IMAPLog("c:\imap.log") imap.Login() Dim mf As MailFolder = imap.SelectInbox() 'grab the BodyStructure of the newest message Dim count As Integer = mf.MessageCount Dim bs As BodyStructure = mf.FetchClient.BodyStructure(count, IndexType.Ordinal) Dim attachments As BodyStructureAttachment() = bs.Attachments() Dim bsa As BodyStructureAttachment For Each bsa In attachments 'write out the name and the id Console.WriteLine("{0}:{1}", bsa.BodyStructureId, bsa.Name) Next bsa Console.WriteLine("Done") Console.ReadLine()