Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
Read Email Headers and List Attachments
VB.NET example program showing how to read a headers from a mailbox on an IMAP server and list attachment information. ' Read email headers from IMAP mailbox and show attachment ' filenames and sizes. Dim imap As New Chilkat.Imap ' Anything unlocks the component and begins a fully-functional 30-day trial. success = imap.UnlockComponent("Anything for 30-day trial") If (success <> true) Then MsgBox(imap.LastErrorText) Exit Sub End If ' If SSL is required, set the Port and Ssl properties: 'imap.Port = 993 'imap.Ssl = True ' Connect to an IMAP server. success = imap.Connect("mail.chilkatsoft.com") If (success <> true) Then MsgBox(imap.LastErrorText) Exit Sub End If ' Login If Not (imap.Login("myLogin", "myPassword")) Then MessageBox.Show(imap.LastErrorText) Exit Sub End If ' Select a mailbox If (Not imap.SelectMailbox("Inbox")) Then MessageBox.Show(imap.LastErrorText) Exit Sub End If ' Get ALL messages. Dim msgSet As Chilkat.MessageSet msgSet = imap.Search("ALL", True) If (msgSet Is Nothing ) Then MsgBox(imap.LastErrorText) Exit Sub End If ' Fetch email headers into a bundle object. Dim bundle As New Chilkat.EmailBundle bundle = imap.FetchHeaders(msgSet) If (bundle Is Nothing ) Then MsgBox(imap.LastErrorText) Exit Sub End If Dim email As Chilkat.Email Dim i As Long For i = 0 To bundle.MessageCount - 1 email = bundle.GetEmail(i) ListBox1.Items.Add("-") ListBox1.Items.Add(email.Subject) ' We cannot use the email.NumAttachments property ' because we only fetched the headers. For this, we must ' use the Chilkat.Imap methods that fetch attachment information ' from downloaded headers. The GetMailNumAttach, GetMailAttachFilename, ' and GetMailAttachSize methods do not communicate with the IMAP server. ' Rather, they extract the attachment information that was provided ' by the IMAP server when the headers were downloaded. Dim numAttach As Long numAttach = imap.GetMailNumAttach(email) ListBox1.Items.Add("number of attachments = " + Str(numAttach)) If (imap.GetMailNumAttach(email) > 0) Then Dim j As Long For j = 0 To numAttach - 1 ListBox1.Items.Add(" " + imap.GetMailAttachFilename(email, j) + _ ", size = " + Str(imap.GetMailAttachSize(email, j))) Next End If Next |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.