none
Creating Soap Message - Can't insert HTML text in the Body of the message RRS feed

  • Question

  • Hi,

    I am building an application to send e-mails using EWS. The application creates a SOAP message with the e-mail contents. I'd like to include HTML in the body of my message. My message looks like this:

    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_SP2" />
      </soap:Header>
      <soap:Body>
        <m:CreateItem MessageDisposition="SaveOnly">
          <m:SavedItemFolderId>
            <t:DistinguishedFolderId Id="sentitems">
            <t:Mailbox>
            <t:EmailAddress>myid@xxx.com</t:EmailAddress>
                </t:Mailbox>
           </t:DistinguishedFolderId>            
          </m:SavedItemFolderId>
          <m:Items>
            <t:Message>
              <t:Subject>Statement of Account</t:Subject>
              <t:Body BodyType="HTML">"Dear member,
    As requested, please find attached your Statement of Account.
    Your Statement of Account provides information about your account balance for the current and previous year.
    It does not itemize specific payments made.
    You can view and print your latest Statement of Account at any time by visiting the member portal at
    <a href='http://www.xxx.com/login'>xxx.com/login</a>."</t:Body> ......

    I get the following error:

    The request failed schema validation: The element 'http://schemas.microsoft.com/exchange/services/2006/types:Body' cannot contain child element 'a' because the parent element's content model is text only

    How can I include HTML in the body of the message?

    Thanks!

    Wednesday, September 4, 2013 3:49 PM

Answers

  • You need to escape any HTML tag you put in (like you would with any SOAP message) eg

      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="
    http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://sc
    hemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xml
    soap.org/soap/envelope/">
        <soap:Header>
          <t:RequestServerVersion Version="Exchange2013" />
          <t:MailboxCulture>en-AU</t:MailboxCulture>
          <t:TimeZoneContext>
            <t:TimeZoneDefinition Id="Eastern Standard Time" />
          </t:TimeZoneContext>
        </soap:Header>
        <soap:Body>
          <m:CreateItem MessageDisposition="SendAndSaveCopy">
            <m:SavedItemFolderId>
              <t:DistinguishedFolderId Id="sentitems" />
            </m:SavedItemFolderId>
            <m:Items>
              <t:Message>
                <t:Subject>test send</t:Subject>
                <t:Body BodyType="HTML">@&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;bo
    dy&gt;This is a &lt;b&gt;test&lt;/b&gt;&lt;em&gt;message&lt;/em&gt;.&lt;br&gt;&l
    t;br&gt;&lt;/body&gt;&lt;/html&gt;</t:Body>
                <t:ToRecipients>
                  <t:Mailbox>
                    <t:EmailAddress>user@domain.com</t:EmailAddres
    s>
                  </t:Mailbox>
                </t:ToRecipients>
              </t:Message>
            </m:Items>
          </m:CreateItem>
        </soap:Body>
      </soap:Envelope>

    Cheers
    Glen
    • Marked as answer by Aldo Bravo Thursday, September 5, 2013 1:18 PM
    Thursday, September 5, 2013 5:08 AM

All replies

  • You need to escape any HTML tag you put in (like you would with any SOAP message) eg

      <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="
    http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://sc
    hemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xml
    soap.org/soap/envelope/">
        <soap:Header>
          <t:RequestServerVersion Version="Exchange2013" />
          <t:MailboxCulture>en-AU</t:MailboxCulture>
          <t:TimeZoneContext>
            <t:TimeZoneDefinition Id="Eastern Standard Time" />
          </t:TimeZoneContext>
        </soap:Header>
        <soap:Body>
          <m:CreateItem MessageDisposition="SendAndSaveCopy">
            <m:SavedItemFolderId>
              <t:DistinguishedFolderId Id="sentitems" />
            </m:SavedItemFolderId>
            <m:Items>
              <t:Message>
                <t:Subject>test send</t:Subject>
                <t:Body BodyType="HTML">@&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;bo
    dy&gt;This is a &lt;b&gt;test&lt;/b&gt;&lt;em&gt;message&lt;/em&gt;.&lt;br&gt;&l
    t;br&gt;&lt;/body&gt;&lt;/html&gt;</t:Body>
                <t:ToRecipients>
                  <t:Mailbox>
                    <t:EmailAddress>user@domain.com</t:EmailAddres
    s>
                  </t:Mailbox>
                </t:ToRecipients>
              </t:Message>
            </m:Items>
          </m:CreateItem>
        </soap:Body>
      </soap:Envelope>

    Cheers
    Glen
    • Marked as answer by Aldo Bravo Thursday, September 5, 2013 1:18 PM
    Thursday, September 5, 2013 5:08 AM
  • Thanks Glen! That worked!
    Thursday, September 5, 2013 1:18 PM