0 votes
by (520 points)
edited by

I have problem retrieving last 100 message


Dim folderMessage As ImapMessageCollection
mgsSet = New ImapMessageSet
mgsSet.AddRange(1, 100)
folderMessage = IMAP.GetMessageList(mgsSet)

This return : The specified message set is invalid (NO).

Applies to: Rebex Secure Mail

2 Answers

+1 vote
by (58.9k points)
selected by
Best answer

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()

' 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
by (520 points)
Thanks man !
0 votes
by (520 points)
edited by

The range must not exceed the folder message count.