Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
4.1 Create Message Example

4.1 Create Message Example

The following is an example of a CreateItem operation that creates a message. This example creates an email message with only the Subject and Body properties completed, and then it sends the email message to User1 and User2 at Contoso.com. The email message can be set with many more properties, such as attachments, Bcc recipients, categories, sender, and item class. This example shows how to send an email message and save a copy of the message in the default Sent Items folder by using the SendAndSaveCopy method.

The client constructs the request XML and sends it to the server. The newly created message is sent to the server.

  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" 
        xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" 
        xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
      <t:RequestServerVersion Version="Exchange2010" />
    </soap:Header>
    <soap:Body>
      <m:CreateItem MessageDisposition="SendAndSaveCopy">
        <m:SavedItemFolderId>
          <t:DistinguishedFolderId Id="sentitems" />
        </m:SavedItemFolderId>
        <m:Items>
          <t:Message>
            <t:Subject>Interesting</t:Subject>
            <t:Body BodyType="HTML">The merger is finalized.</t:Body>
            <t:ToRecipients>
              <t:Mailbox>
                <t:EmailAddress>User1@Contoso.com</t:EmailAddress>
              </t:Mailbox>
              <t:Mailbox>
                <t:EmailAddress>User2@Contoso.com</t:EmailAddress>
              </t:Mailbox>
            </t:ToRecipients>
          </t:Message>
        </m:Items>
      </m:CreateItem>
    </soap:Body>
  </soap:Envelope>

The server constructs the response XML and sends it to the client.

  <?xml version="1.0" encoding="utf-8"?>
  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
      <h:ServerVersionInfo MajorVersion="14" 
          MinorVersion="1" 
          MajorBuildNumber="63" 
          MinorBuildNumber="0" 
          Version="Exchange2010" 
          xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" 
          xmlns="http://schemas.microsoft.com/exchange/services/2006/types" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    </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="Success">
            <m:ResponseCode>NoError</m:ResponseCode>
            <m:Items />
          </m:CreateItemResponseMessage>
        </m:ResponseMessages>
      </m:CreateItemResponse>
    </s:Body>
  </s:Envelope>
Show:
© 2015 Microsoft