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;
}
headers
`, but `"%3Ch1%3E%20headers%20%3C/h1%3E"` – Tholle Oct 26 '15 at 17:53