I need to create an email, attach another email message to it and save it into drafts folder;
To proceed, I use first GetItem
, then CreateItem
.
But each time it appears 2 email messages in that folder. Each email message contains the attachment and is in draft mode. I don't understand why there is 2 email messages.
Please help me. Thank you.
Here is my code:
(function () {
"use strict";
Office.initialize = function (reason) {
$(document).ready(function () {
app.initialize();
$('#fowardToGroups').click(function () { sendNow(); });
});
};
var item_id;
var mailbox;
async function sendNow() {
var item = Office.context.mailbox.item;
item_id = item.itemId;
mailbox = Office.context.mailbox;
var receiver="[email protected]";
var soapToCreateItem='<?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:t="http://schemas.microsoft.com/exchange/services/2006/types"'+
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
' <soap:Header>'+
' <t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />'+
' </soap:Header>'+
' <soap:Body>'+
' <m:CreateItem MessageDisposition="SaveOnly">'+
' <m:SavedItemFolderId> '+
' <t:DistinguishedFolderId Id="drafts" /> '+
' </m:SavedItemFolderId> '+
' <m:Items>'+
' <t:Message>'+
' <t:Subject>Suspicious e-mail </t:Subject>'+
' <t:Body BodyType="HTML">body</t:Body>'+
' <t:ToRecipients>'+
' <t:Mailbox>'+
' <t:EmailAddress>'+receiver+'</t:EmailAddress>'+
' </t:Mailbox>'+
' </t:ToRecipients>'+
' </t:Message>'+
' </m:Items>'+
' </m:CreateItem>'+
' </soap:Body>'+
' </soap:Envelope>';
mailbox.makeEwsRequestAsync(soapToCreateItem, soapToCreateItemCallback);
}
function soapToCreateItemCallback(asyncResult) {
var parser;
var xmlDoc;
if (asyncResult.error != null) {
app.showNotification("EWS Status 1", asyncResult.error.message);
}
else {
var response = asyncResult.value;
if (window.DOMParser) {
parser = new DOMParser();
xmlDoc = parser.parseFromString(response, "text/xml");
}
else // Older Versions of Internet Explorer
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.loadXML(response);
}
var result = xmlDoc.getElementsByTagName("m:ResponseCode")[0].textContent;
if (result == "NoError") {
app.showNotification("Status", "Success !");
}
else {
app.showNotification("Status", "error : " + result);
}
}
}
})();