1

I want to append some text to the beginning of the body of an email I'm forwarding (via a web Mail Addin/JavaScript for Office) using CreateItem with a ForwardItem element. The text I'm inserting is complex and seems to generate various ErrorSchemaValidation errors. Here's what I've tried for the value of the NewBodyContent element (with BodyType="HTML"; the body text is passed via the headers parameter):

  • Used complex text (in this case the full Internet Message headers from another email) - fails, no text is appended
  • Used encodeURI on complex text - works, but all the encoded values are not transformed to HTML and the appended text appears as Plain Text (although source body is still HTML; e.g. the appended text reads as "From:%20username %20%3Cuser@domain.com%3E%0A" instead of "From: username <user@domain.com>")
  • Inserted 'Hello world!' - works
  • Inserted '<H1>Hello world!</H1>' - fails, no text is appended

I'm baffled. Any ideas on how to properly append complex text to the HTML body?

function forwardItemRequest(item_id, email, changeKey, headers) {
    var request;

    // The following string is a valid SOAP envelope and request for forwarding
    // a mail item. Note that we use the item_id value to specify the item we are interested in,
    // along with its ChangeKey value that we have just determined
    // We also provide the XML fragment to specify the recipient addresses

    //TEST 5: Try with HTML content
    request = '<?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:xsd="http://www.w3.org/2001/XMLSchema"' +
        '               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
        '               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
        '  <soap:Header>' +
        '    <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
        '  </soap:Header>' +
        '  <soap:Body>' +
        '    <m:CreateItem MessageDisposition="SendAndSaveCopy">' +
        '      <m:Items>' +
        '        <t:ForwardItem>' +
        '          <t:ToRecipients>' + email + '</t:ToRecipients>' +
        '          <t:ReferenceItemId Id="' + item_id + '" ChangeKey="' + changeKey + '" />' +
        '          <t:NewBodyContent BodyType="HTML">' + headers + '</t:NewBodyContent>' +
        '        </t:ForwardItem>' +
        '      </m:Items>' +
        '    </m:CreateItem>' +
        '  </soap:Body>' +
        '</soap:Envelope>';


    return request;
}
Eric Legault
  • 5,706
  • 2
  • 22
  • 38
  • Try escping the `headers` variable and it should work. I.e., not `

    headers

    `, but `"%3Ch1%3E%20headers%20%3C/h1%3E"`
    – Tholle Oct 26 '15 at 17:53
  • If I set header to "%3Ch1%3E%20" + headers + "%20%3C/h1%3E" I get schema validation errors. If I just set headers = "%3Ch1%3E%20Hello World%20%3C/h1%3E" that's exactly what comes out - it doesn't get read as HTML. – Eric Legault Oct 26 '15 at 18:23
  • My bad. Try the following: `<h1> headers </h1>` (HTML entities used instead) – Tholle Oct 26 '15 at 19:37
  • 1
    Thanks to Glen Scales for pointing out this method: http://stackoverflow.com/questions/1219860/html-encoding-in-javascript-jquery – Eric Legault Oct 27 '15 at 18:19

0 Answers0