The following example demonstrates how to download an attachment, by
the attachment's name.
[C#]
IMAP4 imap = new IMAP4( "127.0.0.1", "dave@blah.com", "test" ); //set some logging properties imap.Logger = new IMAPLog(); imap.Logger.Overwrite = true; imap.Logger.InMemory = true; imap.Logger.Path = "c:\\imap.log"; imap.Login(); MailFolder mf = imap.SelectInbox(); //downloads an attachment named 'sales.doc' in the first message MimeMessage attachment = mf.FetchClient.DownloadAttachment( 1, "sales.doc", IndexType.Ordinal, false ); if( attachment != null ) { attachment.Save( "c:\\temp" ); } imap.Disconnect(); //write out the log Console.WriteLine( imap.Logger.ToString() ); Console.WriteLine( "Done" ); Console.ReadLine();
[VB.NET]
Dim imap As New IMAP4("127.0.0.1", "dave@blah.com", "test") 'set some logging properties imap.Logger = New IMAPLog() imap.Logger.Overwrite = True imap.Logger.InMemory = True imap.Logger.Path = "c:\imap.log" imap.Login() Dim mf As MailFolder = imap.SelectInbox() 'downloads an attachment named 'sales.doc' in the first message Dim attachment As MimeMessage = mf.FetchClient.DownloadAttachment(1, "sales.doc", IndexType.Ordinal, False) If Not (attachment Is Nothing) Then attachment.Save("c:\temp") End If imap.Disconnect() 'write out the log Console.WriteLine(imap.Logger.ToString()) Console.WriteLine("Done") Console.ReadLine()