0

When replying to an email the send request happens asynchronously which means that the message id is not returned in the response.

According to Microsoft the solution is to add an ExtendedProperty to the message to act as a unique id which can later be used to find the newly sent email using a Restriction in FindItem.

I have succeeded in doing this when sending a regular email, as follows:

<ns2:CreateItem MessageDisposition="SendAndSaveCopy">
    <ns2:SavedItemFolderId>
        <ns1:DistinguishedFolderId Id="sentitems"/>
    </ns2:SavedItemFolderId>
    <ns2:Items>
        <ns1:Message>
            <ns1:ItemClass>IPM.Note</ns1:ItemClass>
            <ns1:Subject>Test create item</ns1:Subject>
            <ns1:Body BodyType="Text">And here is the body</ns1:Body>
            <ns1:ExtendedProperty>
                <ns1:ExtendedFieldURI 
                     PropertyName="CustomId" 
                     PropertySetId="SOME SET ID" 
                     PropertyType="String"
                />
                <ns1:Value>UNIQUE ID</ns1:Value>
            </ns1:ExtendedProperty>
            <ns1:ToRecipients>
                <ns1:Mailbox>
                    <ns1:EmailAddress>my@email.com</ns1:EmailAddress>
                </ns1:Mailbox>
            </ns1:ToRecipients>
        </ns1:Message>
    </ns2:Items>
</ns2:CreateItem>

The problem is that when trying to add the ExtendedProperty to a Message contained in ReplyAllToItem, the field is not included in the request.

<ns2:CreateItem MessageDisposition="SaveOnly">
    <ns2:SavedItemFolderId>
        <ns1:DistinguishedFolderId Id="sentitems"/>
    </ns2:SavedItemFolderId>
    <ns2:Items>
        <ns1:ReplyAllToItem>
            <ns1:Subject>Subject</ns1:Subject>
            <ns1:ToRecipients>
                <ns1:Mailbox>
                    <ns1:EmailAddress>my@email.com</ns1:EmailAddress>
                </ns1:Mailbox>
            </ns1:ToRecipients>
            <ns1:CcRecipients/>
            <ns1:ReferenceItemId ChangeKey="CQ=" Id="AA="/>
                <ns1:NewBodyContent BodyType="HTML">Body</ns1:NewBodyContent>
            </ns1:ReplyAllToItem>
        </ns2:Items>
    </ns2:CreateItem>

By the way I am using php-ews to build the requests.

Developer
  • 736
  • 7
  • 30

1 Answers1

1

I don't believe the underlying types for that operation allow you to add an Extended property. As easy workaround for that is to save the Message first to the drafts folder

      <m:CreateItem MessageDisposition="SaveOnly">
    <m:SavedItemFolderId>
      <t:DistinguishedFolderId Id="drafts" />
    </m:SavedItemFolderId>
    <m:Items>
      <t:ReplyAllToItem>
        <t:ReferenceItemId Id="AAMkADczN..." ChangeKey="CQAA..." />
      </t:ReplyAllToItem>
    </m:Items>
  </m:CreateItem>

You will then get returned a ItemId to the underlying EmailMessage that gets created by ReplyToAllToItem, you can then just use a normal updateItem request on that email and then send it with the SendItem operation. Its a few more requests but should work okay.

Glen Scales
  • 20,495
  • 1
  • 20
  • 23