Error at Sending an email with attachments by ews - ServiceResponseException - The operation can't be performed because the item is out of date

Steve Baier 1 Reputation point
2022-05-27T05:45:52.027+00:00

Hello,

we send emails with attachments by the ews-service with the follwing code...

EmailMessage message = new EmailMessage(ExchangeServiceController);

EmailAddress sender = new EmailAddress
{
 MailboxType = MailboxType.Mailbox,
 Address = senderAdress
};

message.From = sender;
message.ToRecipients.AddRange(email.SendTo.GetEmailAdressRange());
message.Subject = email.Subject;
message.Body = new MessageBody(BodyType.HTML, emailText);

string[] fileEntries = SignatureController.GetSignatureImagesFiles();
int i = 0;

foreach (string fileName in fileEntries.Where(f => f.Contains("image")))
{
 FileInfo info = new FileInfo(fileName);

 message.Attachments.AddFileAttachment(info.Name, fileName);
 message.Attachments[i].IsInline = true;
 message.Attachments[i].ContentId = info.Name;
 i++;
}

foreach (string filename in GetAttachmentsAsFilePathList())
{
 message.Attachments.AddFileAttachment(filename);
}

var mailbox = new Mailbox(sender.Address);
var folderIdDrafts = new FolderId(WellKnownFolderName.Drafts, mailbox);
var folderIdSent = new FolderId(WellKnownFolderName.SentItems, mailbox);

// save email at draft to get the mime-content
message.Save(folderIdDrafts);
message.Load(new PropertySet(ItemSchema.MimeContent));
email.EmlContent = message.MimeContent;

if (template.SaveMessageOnSend)
{
 message.SendAndSaveCopy(folderIdSent);
}
else
{
 message.Send();
}

The email saved in draft. After this we get sometimes an follwoing error...

Type: Microsoft.Exchange.WebServices.Data.ServiceResponseException
Source: Microsoft.Exchange.WebServices
Message: The operation can't be performed because the item is out of date. Reload the item and try again.
HResult: -2146233088 (0x80131500)
InnerException: null
HashedSignature: 49E2BF981546C920B6A4BC0B27476A40
StackTrace:
bei Microsoft.Exchange.WebServices.Data.ServiceResponse.InternalThrowIfNecessary()
bei Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
bei Microsoft.Exchange.WebServices.Data.ExchangeService.SendItem(Item item, FolderId savedCopyDestinationFolderId)
bei Microsoft.Exchange.WebServices.Data.EmailMessage.InternalSend(FolderId parentFolderId, MessageDisposition messageDisposition)

It happens often with attachment over 6 MB.

The timeout is over 1 minute and the error becomes before this time.

The maxsize is over 10 MB

When i take this email at outlook and send it from the draft it works fine.

Have anybody an idea to solve this problem?

best regards steve

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,581 questions
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.
526 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,468 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. medinaMA 1 Reputation point
    2022-08-17T17:33:44.66+00:00

    Good afternoon @Steve Baier , were you ever able to resolve. I ask because i get the same error within an application using EWS. Thanks.