Quantcast
Channel: Rebex Q&A Forum - Recent questions and answers
Viewing all articles
Browse latest Browse all 3862

Answered: IMAP Problem retrieving only last 100 messages

$
0
0

Most probably your folder does not contain 100 messages and that's why you get the error. Try this code:

Dim imap As New Imap()
imap.Connect("server")
imap.Login(...)
imap.SelectFolder("INBOX")

' maximum number of newest messages to retrieve
Dim limit As Integer = 100

' calculate the range (there can be less messages in the inbox than the limit specified)
Dim last As Integer = imap.CurrentFolder.TotalMessageCount
Dim first As Integer = Math.Max(1, last - limit + 1)

' construct an ImapMessageSet
Dim messageSet As New ImapMessageSet()
messageSet.AddRange(first, last)

' retrieve the messages

Dim messages = imap.GetMessageList(messageSet)

Console.WriteLine("count = " + messages.Count.ToString())

' iterate through the messages (from newer to older) and write subject:
For index = messages.Count - 1 To 0 Step -1
        Console.WriteLine(messages(index).Subject)
Next

Viewing all articles
Browse latest Browse all 3862

Trending Articles