Here is the code, I am using to do paging. I am showing emails in a grid, would like to pull only the 15 emails in the current page.
using (var imap = new Imap())
{
imap.ConnectSSL(provider.EmailServer, provider.EmailPort);
imap.SendCommand(@"ID (""GUID"" ""1"")");
imap.Login(provider.EmailUserName, provider.EmailPassword);
imap.SelectInbox();
List<long> uids = imap.GetAll();
totalMailCount = uids.Count;
var filter = new List<long>();
if (totalMailCount > pageSize)
{
filter = uids.Skip(pageNumber).Take(pageSize).ToList();
}
else
{
filter = uids;
}
List<MessageInfo> infos = imap.GetMessageInfoByUID(filter);
foreach (MessageInfo info in infos)
{
var item = new MailItem();
item.Subject = info.Envelope.Subject;
var from = info.Envelope.From.First();
item.FromEmailAddress = from.Address;
item.FromName = from.Name;
item.FromName = string.IsNullOrEmpty(item.FromName) ?
item.FromEmailAddress :
item.FromName;
item.SentDate = info.Envelope.Date.Value;
item.Id = (int)info.UID;
item.AttachmentCount = info.BodyStructure.Attachments.Count;
item.UIDL = info.UID.ToString();
list.Add(item);
}
imap.Close();
}
Please let me know, if there is a better way to do this.
Thanks for your help, I appreciate it.
Have tried several components, so far this is the fastest.