0

我需要创建一封电子邮件,附加另一封电子邮件并将其保存到草稿文件夹中;

要继续,我先使用GetItem,然后使用CreateItem

但每次在该文件夹中出现 2 封电子邮件。每封电子邮件都包含附件并且处于草稿模式。我不明白为什么有 2 封电子邮件。

请帮我。谢谢你。

这是我的代码:

(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="test@ymail.com";
            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);
            }
        }
      }

  })();
4

0 回答 0