Sending a message with attachments in a single call fails

skojer 0 Reputation points
2025-01-13T12:03:31.3033333+00:00

I've tried creating a new e-mail with new attachments as per the Microsoft Learn article. However, I'm getting the error "Set action is invalid for property" with the FieldURI being "item:Attachments".

My request is as follows:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <soap:Body>
    <CreateItem MessageDisposition="SendAndSaveCopy" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
    <SavedItemFolderId>
        <t:DistinguishedFolderId Id="sentitems"/>
      </SavedItemFolderId>
    <Items>
        <t:Message>
          <t:Subject>Test Subject</t:Subject>
          <t:Body BodyType="HTML">Test Bodyn</t:Body>
		<t:Attachments>
            <t:FileAttachment>
              <t:Name>FileAttachment.txt</t:Name>
              <t:Content></t:Content>
            </t:FileAttachment>
          </t:Attachments>
          <t:ToRecipients>
            <t:Mailbox>
              <t:EmailAddress>test@test.com</t:EmailAddress>
            </t:Mailbox>
          </t:ToRecipients>
        </t:Message>
      </Items>
    </CreateItem>
  </soap:Body>
</soap:Envelope>

For posterity, the response I get is

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Header>
      <h:ServerVersionInfo MajorVersion="15" MinorVersion="0" MajorBuildNumber="1497" MinorBuildNumber="0" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
   </s:Header>
   <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <m:CreateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
         <m:ResponseMessages>
            <m:CreateItemResponseMessage ResponseClass="Error">
               <m:MessageText>Set action is invalid for property.</m:MessageText>
               <m:ResponseCode>ErrorInvalidPropertySet</m:ResponseCode>
               <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
               <m:MessageXml>
                  <t:FieldURI FieldURI="item:Attachments"/>
               </m:MessageXml>
               <m:Items/>
            </m:CreateItemResponseMessage>
         </m:ResponseMessages>
      </m:CreateItemResponse>
   </s:Body>
</s:Envelope>
Microsoft Exchange
Microsoft Exchange
Microsoft messaging and collaboration software.
624 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jake Zhang-MSFT 8,010 Reputation points Microsoft Vendor
    2025-01-14T02:39:22.41+00:00

    Hi @skojer ,

    Welcome to the Microsoft Q&A platform!

    Based on your description, the "Set operation is not valid for the property" error you are encountering seems to be due to the way the attachment is handled in the request. This problem usually occurs when the attachment content is not encoded correctly or the attachment format is not correct.

    You can try the following methods to solve this problem:

    1. The attachment content should be Base64 encoded. You can use a Base64 encoding tool to convert the file content to Base64.
    2. Make sure the attachment structure is correct. Here is what it should look like:
    <t:Attachments>
    <t:FileAttachment>
    <t:Name>FileAttachment.txt</t:Name>
    <t:Content>BASE64_ENCODED_CONTENT</t:Content>
    </t:FileAttachment>
    </t:Attachments>
    
    1. Another method is to save the message without sending it, then add the attachment, and finally send the message. This method works in some cases.
    2. Make sure your Exchange server version supports the operation you are trying to perform. Some older versions may not support certain features.

    Please feel free to contact me for any updates. And if this helps, don't forget to mark it as an answer.

    Best,

    Jake Zhang

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.