I'm using GemBox.Email and I'm retrieving unread emails from my inbox like this:
using (var imap = new ImapClient("imap.gmail.com"))
{
imap.Connect();
imap.Authenticate("username", "password");
imap.SelectInbox();
IEnumerable<string> unreadUids = imap.ListMessages()
.Where(info => !info.Flags.Contains(ImapMessageFlags.Seen))
.Select(info => info.Uid);
foreach (string uid in unreadUids)
{
MailMessage unreadEmail = imap.GetMessage(uid);
unreadEmail.Save(uid + ".eml");
}
}
The code is from the Receive example, but the problem is that after retrieving them they end up being marked as read in my inbox.
How can I prevent this from happening?
I want to download them with ImapClient and leave them as unread on email server.
EDIT (2021-01-19):
Please try again with the latest version from the BugFixes page or from NuGet.
The latest version provides
ImapClient.PeekMessagemethods which you can use like this:ORIGINAL:
When retrieving an email, most servers will mark it with the "SEEN" flag. If you want to leave an email as unread then you can just remove the flag.
Also, instead of using
ImapClient.ListMessagesyou could useImapClient.SearchMessageUidsto get IDs of unread emails.So, try the following: