1
votes

When I'm sending a message i'm not able to get a 'ServiceResponse' object because the function i'm using the send the mail doesn't support it.

                    ServiceResponseCollection<ServiceResponse> response = service.CreateItems(new Collection<EmailMessage>() { EmailMsg }, WellKnownFolderName.SentItems, MessageDisposition.SendAndSaveCopy, null);

When using this code if one of my messages has an attachment it will throw me this error (This operation doesn't support items that have attachments.) It works fine when sending emails with no attachments.

I can alternative use this to send the email and it works fine with attachments, but it returns void so I can't check the ServiceResponse.

EmailMsg.SendAndSaveCopy(WellKnownFolderName.SentItems); 

I need to either get a ServiceReponse object back or just a plain httpresponse for emails with attachments. I can't even find the error (This operation doesn't support items that have attachments.) when I google it. I'm using EWS managed api 2.0 and it's hitting ExchangeServer 2007 sp1

1

1 Answers

0
votes

Under the hood, the workflow for sending emails with attachments is: CreateItem, CreateAttachment, and then SendItem. ExchangeService.CreateItems is a batch of CreateItem calls, it doesn't contain the workflow to break out items with attachments.

I suggest that you build two collections: one that contains emails w/ attachments, another for email w/o attachments. Send emails w/o attachments in bulk. You will have to send emails w/ attachments individually since CreateAttachment doesn't have a batch option.

Since EmailMessage.SendAndSaveCopy does not return an object with status, I think you'll need to rely on exception handling to determine whether the email with an attachment was successfully sent.