Microsoft.Exchange.WebServices.Data.EmailMessage error "The operation can't be performed because the item is out of date. Reload the item and try again"

David Joyce 150 Reputation points
2024-05-23T08:49:37.1566667+00:00

Hi,

I have been using Microsoft Exchange Web Services for a couple of years in my asp.net c# system and had no issues.

Last week 1 customer started getting below error, then yesterday another customer and 2 more today!

Microsoft.Exchange.WebServices.Data.EmailMessage error "The operation can't be performed because the item is out of date. Reload the item and try again"

Could you please advise why this may happen and what possible ways are to resolve this?

Regards & Thanks,

David

Exchange Server Development
Exchange Server Development
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Development: The process of researching, productizing, and refining new or existing technologies.
525 questions
{count} votes

Accepted answer
  1. Philippe Van Cauwenbergh 85 Reputation points
    2024-05-24T10:03:17.2533333+00:00

    I have a work around.

    I noticed that when the error occured, the mail was in the drafts folder, but got stuck there.

    Work around;

    Step 1 : instead of message.send() or message.sendandsave() , use message.Save(WellKnownFolderName.Drafts);

    Step 2 : read the drafts folder (you can make a filter list of the mails in the drafts folder) and sendandsave() the drafts mail.

            try
    
            {
    
                var cca = ConfidentialClientApplicationBuilder
    
                                            .Create(L_FactuurmailAppid)
    
                                            .WithClientSecret(L_FactuurmailClientSecret)
    
                                            .WithTenantId(L_FactuurmailTenant)
    
                                            .Build();
    
                var ewsScopes = new string[] { "https://outlook.office365.com/.default" };
    
                var authResult = cca.AcquireTokenForClient(ewsScopes).ExecuteAsync().GetAwaiter().GetResult();
    
                ExchangeService exchange = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
    
                exchange.Timeout = 100000000;
    
                exchange.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
    
                exchange.Credentials = new OAuthCredentials(authResult.AccessToken);
    
                // exchange.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, L_FactuurmailFrom);
    
                exchange.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "your_email_adres@test.com");
    
                exchange.Timeout = 1000000;
    
                exchange.KeepAlive = true;
    
                //// verstuur alle mails uit DRAFTS FOLDER
    
                // Bind to the Drafts folder
    
                FolderId draftsFolderId = new FolderId(WellKnownFolderName.Drafts);
    
                // Define a search filter for the subject containing "your_mailsubject_selection_text"
    
                SearchFilter searchFilter = new SearchFilter.ContainsSubstring(ItemSchema.Subject, "your_mailsubject_selection_text");
    
                // Define the item view to specify the number of items to retrieve
    
                ItemView view = new ItemView(100); // Adjust the number if needed
    
                // Find items in the Drafts folder matching the search filter
    
                FindItemsResults<Item> draftItems = exchange.FindItems(draftsFolderId, searchFilter, view);
    
                foreach (Item item in draftItems.Items)
    
                {
    
                    if (item is EmailMessage draftEmail)
    
                    {
    
                        // Send the email
    
                        draftEmail.SendAndSaveCopy();
    
                    }
    
                }
    
            }
    
            catch (Exception ex)
    
            {
    
                MessageBox.Show("Sending from DRAFTS FOLDER failes !\n" + ex.Message.ToString());
    
            }
    ```Hope this helps
    
    Additional notice:
    
    I was too optimistic. I had to build a loop around the emails in Drafts folder untill Drafts folder is empty
    
    
    2 people found this answer helpful.

11 additional answers

Sort by: Most helpful
  1. David Barrett 21 Reputation points Microsoft Employee
    2024-05-30T09:19:31.6066667+00:00

    The error message is telling you what the issue is - the item that you have a copy of has been updated on the server in the meantime, so your copy is stale and needs to be reloaded. You'll get this error if the ChangeKey you send in your request does not match the ChangeKey of the item on the server.

    This is something that needs to be handled by the client (by reloading the message, or simply retrying the request with the up-to-date ChangeKey).


  2. AdamG 0 Reputation points
    2024-05-31T12:19:21.5966667+00:00

    Same issue, is there some sort of tracker with updates to this? It seems like kind of a big deal...

    0 comments No comments

  3. Thomas Haack 5 Reputation points
    2024-05-31T13:44:26.3966667+00:00

    This issue is affecting our tenant as well. If anyone gets an issue tracking ID or something of that sort, will you please update the post so I can add it to our case?

    Thanks!

    0 comments No comments

  4. Andrea Scianti 0 Reputation points
    2024-06-03T07:55:07.3766667+00:00

    We are having same problem, any news?

    0 comments No comments