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. Phil Bailey 21 Reputation points
    2024-06-03T21:54:36.5466667+00:00

    Also having this issue. Using work around but would appreciate update.

    0 comments No comments

  2. Sven Sipido 0 Reputation points
    2024-06-04T07:52:33.5666667+00:00

    Any news on this?


  3. Rabin Panichnok 0 Reputation points
    2024-06-13T23:14:03.2266667+00:00

    Still error until this time. No updates at all.

    0 comments No comments