Reputation: 111
I have the list of unique keys of unseen emails and my current logic is to process it in one session/connection. However, sometimes server[rebex] crashes and sends an error *
Rebex.Net.ImapException: The server has closed the connection.
at below point.
Here, it will mark particular email's status seen though it generates an error. So, next time if I try to get information of unseen emails this particular unique key email will be missed.
Here, I have explored some possible ways
Are there any more optimized solutions? Thanks
Upvotes: 1
Views: 735
Reputation: 1558
You can prevent GetMailMessage
from marking email as seen using Imap
object's Settings.UsePeekForGetMessage
option:
var imap = new Imap();
imap.Settings.UsePeekForGetMessage = true;
...
Once you actually decide to mark the email as seen, use SetMessageFlags
method:
imap.SetMessageFlags(unique_key, ImapFlagAction.Add, ImapMessageFlags.Seen);
Upvotes: 4
Reputation: 9685
The classic response is to mark messages as processed after processing instead of before.
Which may lead to problems if a processing a particular message leads to a crash. One doesn't want to reconnect and immediately run into the same problem. So perhaps keep a record of when you last tried, and try messages oldest-first.
Upvotes: 1