Chilkat HOME Android™ ASP Visual Basic VB.NET C# iOS (IPhone) Objective-C C++ C Unicode C++ Unicode C MFC Delphi DLL Delphi ActiveX FoxPro Java Perl PHP Extension PHP ActiveX Python PowerShell Ruby SQL Server VBScript
(VB.NET) Fetch 1st N Headers of Search ResultsCalls Search to get a message set, then downloads the 1st N messages in the message set. There are two equivalent ways of doing it: (1) iterate from 0 to N-1 and download each message individually, or (2) create a new message set that contains the 1st N messages and pass it to FetchHeaders. Both are demonstrated here. Download: Chilkat .NET Assemblies Dim imap As New Chilkat.Imap() Dim success As Boolean ' Anything unlocks the component and begins a fully-functional 30-day trial. success = imap.UnlockComponent("Anything for 30-day trial") If (success <> true) Then TextBox1.Text = TextBox1.Text & imap.LastErrorText & vbCrLf Exit Sub End If ' Connect to an IMAP server. success = imap.Connect("mail.chilkatsoft.com") If (success <> true) Then TextBox1.Text = TextBox1.Text & imap.LastErrorText & vbCrLf Exit Sub End If ' Login success = imap.Login("****","****") If (success <> true) Then TextBox1.Text = TextBox1.Text & imap.LastErrorText & vbCrLf Exit Sub End If ' Select an IMAP mailbox success = imap.SelectMailbox("Inbox") If (success <> true) Then TextBox1.Text = TextBox1.Text & imap.LastErrorText & vbCrLf Exit Sub End If Dim messageSet As Chilkat.MessageSet ' We can choose to fetch UIDs or sequence numbers. Dim fetchUids As Boolean fetchUids = true ' Get the message IDs of all the emails in the mailbox messageSet = imap.Search("ALL",fetchUids) If (messageSet Is Nothing ) Then TextBox1.Text = TextBox1.Text & imap.LastErrorText & vbCrLf Exit Sub End If Dim numFound As Long numFound = messageSet.Count If (numFound = 0) Then TextBox1.Text = TextBox1.Text & "No messages found." & vbCrLf Exit Sub End If ' Get the 1st 10 messages in messageSet. Dim maxToGet As Long maxToGet = 10 Dim upperBound As Long upperBound = 10 If (numFound < upperBound) Then upperBound = numFound End If Dim i As Long Dim bUid As Boolean bUid = messageSet.HasUids For i = 0 To upperBound - 1 Dim email As Chilkat.Email email = imap.FetchSingleHeader(messageSet.GetId(i),bUid) If (email Is Nothing ) Then TextBox1.Text = TextBox1.Text & imap.LastErrorText & vbCrLf Exit Sub Else ' Do whatever is needed with the email.. ' .... End If Next ' Alternatively, create a new message set containing the 1st 10 message id's (UID's) ' from the search results message set: Dim firstTen As New Chilkat.MessageSet() For i = 0 To upperBound - 1 firstTen.InsertId(messageSet.GetId(i),bUid) Next ' Download the 1st ten headers: Dim bundle As Chilkat.EmailBundle bundle = imap.FetchHeaders(firstTen) If (bundle Is Nothing ) Then TextBox1.Text = TextBox1.Text & imap.LastErrorText & vbCrLf Exit Sub End If ' Other examples show how to iterate over the emails contained within the bundle... ' Disconnect from the IMAP server. imap.Disconnect() |
© 2000-2013 Chilkat Software, Inc. All Rights Reserved.