Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The application may access the same mailbox from two different computers and retrieve unread emails. I'd like to change mail status to Read immediately on mail retrieving to avoid downloading the same email to multiple stations.

What I have tried:

FindItemsResults<Item> emails = _service.FindItems(WellKnownFolderName.Inbox, _searchFilter_Unread, _itemView_Retrieve);
foreach (EmailMessage email in emails)
{
    email.IsRead = true;
    email.Update(ConflictResolutionMode.AlwaysOverwrite);
}

This code works, but it takes time to update the email state, so it may occur that the same email is downloaded to multiple stations.

Thank you.
Posted
Updated 11-May-22 2:51am
v2
Comments
[no name] 11-May-22 15:27pm    
Sounds like a client pull system. You should have a separate app queue the emails on some "other" server and have the clients pull from the queue; LIFO or FIFO or priority, etc. Unless it's not that important.
Haifovchanin 12-May-22 2:39am    
You are right, it is a client pull system.
Thank you, Gerry. I'll think how to implement the proposed synchronization with all our current restrictions.

1 solution

That's not how an email server works. You cannot guarantee both machines will NOT get the same email. No, you cannot download the emails and simultaneously mark them as read.

While machine1 is downloading the emails, machine2 can be doing the exact same thing as the exact same time.

While machine1 is going through the emails and marking them "read", machine 2 can download the remaining "unread" emails.

There's no way to prevent this.

YOu would be much better off having one machine read the emails and populating either a database or a message queue with work items and having multiple machines pickup those records/jobs one at a time and doing whatever work they need to on each.
 
Share this answer
 
Comments
Haifovchanin 11-May-22 9:21am    
Thank you, Dave.
The problem is that the stations are independent and have no connection to each other. Another fact, that may make things easier: the unread emails are downloaded one by one on user's click and the time between clicks is measured in minutes.
Is there is a way to synchronize the access to unread emails to avoid simultaneous downloading if the same email?
Dave Kreskowiak 11-May-22 9:34am    
No, you cannot guarantee it.
Haifovchanin 12-May-22 2:01am    
Understood.
Thank you, Dave.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900