无法向Office JS加载项添加附件

问题描述 投票:0回答:2

我创建了一个附加电子邮件的EWS请求,但是我收到了空值,但状态为“成功”。顺便说一句。

我首先创建了一个makeEwsRequestAsync请求,用于将电子邮件保存到草稿,它已经可以工作但是当我尝试使用此请求添加附件时它没有添加。任何建议或帮助请

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
function createAttachment() {

    var request =
        '<?xml version="1.0" encoding="utf-8"?>' +
        '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
        '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:Body>' +
        '    <CreateAttachment xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
        '      <ParentItemId Id="'+itemID+'" />' +
        '      <Attachments>' +
        '        <t:ItemAttachment>' +
        '          <t:Name>Please</t:Name>' +
        '           <t:Message>' +
        '               <t:ItemClass>IPM>Note</t:ItemClass>' +
        '               <t:Subject>test</t:Subject>' +
        '               <t:Body BodyType="Text">my test</t:Body>' +
        '           </t:Message>' +
        '        </t:ItemAttachment>' +
        '      </Attachments>' +
        '    </CreateAttachment>' +
        '  </soap:Body>' +
        '</soap:Envelope>';
    return request;
}

</script>

这是我创建附件EWS请求

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">


    function composeMail(emailSubject, emailDescription) {
        var subject= subjectPrefix + " " + emailSubject;
        var request =
            '<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
            '               xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
            '               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>' +
            '    <RequestServerVersion Version="Exchange2007_SP1" />' +
            '  </soap:Header>' +
            '  <soap:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
            '    <m:CreateItem MessageDisposition="SaveOnly">' +
            '      <m:SavedItemFolderId>' +
            '        <t:DistinguishedFolderId Id="drafts" />' +
            '      </m:SavedItemFolderId>' +
            '      <m:Items>' +
            '            <t:Message>' +
            '              <t:ItemClass>IPM.Note</t:ItemClass>' +
            '              <t:Subject>' + subject + '</t:Subject>' +
            '              <t:Body BodyType="HTML">' + emailDescription + '</t:Body>' +
            '              <t:Importance>Low</t:Importance>' +
            '              <t:ToRecipients>' +
            '                <t:Mailbox>' +
            '                  <t:EmailAddress>' + recepient + '</t:EmailAddress>' +
            '                </t:Mailbox>' +
            '              </t:ToRecipients>' +
            '              <t:IsRead>false</t:IsRead>' +
            '            </t:Message>' +
            '          </m:Items>' +
            '        </m:CreateItem>' +
            '  </soap:Body>' +
            '</soap:Envelope>';
        return request;
    }
</script>

这是我创建的电子邮件EWS请求

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
    function send() {
        var request =
            '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
            '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:Body>' +
            '    <SendItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"' +
            '    SaveItemToFolder="true">' +
            '      <ItemIds>' +
            '        <t:ItemId Id="' + itemID + '"/>' +
            '      </ItemIds>' +
            '    </SendItem>' +
            '  </soap:Body>' +
            '</soap:Envelope>';
        return request;
    }

</script>

这是我发送的EWS请求,我正在使用它

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
    function sendRequest(emailSubject, emailDescription, emailItemID) {
        // Create a local variable that contains the mailbox.
        try {
            itemID = Office.context.mailbox.item.itemId;
            Office.context.mailbox.makeEwsRequestAsync(
                composeMail(emailSubject, emailDescription), callbackCompose);
            Office.context.mailbox.makeEwsRequestAsync(
                createAttachment(), callbackAttachment);
            Office.context.mailbox.makeEwsRequestAsync(
                send(), callbackSend);
        } catch (error) {
            $("#id-error-msg").text(error);
        }
</script>
outlook exchangewebservices outlook-addin office-js add-in
2个回答
1
投票

看起来像我的坏XML,例如

'<t:ItemClass>IPM>Note</t:ItemClass>' +

会在服务器上产生验证错误(您应该在服务器的EWS响应中看到,例如您的请求应该是

'<t:ItemClass>IPM.Note</t:ItemClass>'

0
投票

如果要从撰写模式处理电子邮件,可以参考Microsoft团队的此文档。我相信它更加简单和全面。

-https://docs.microsoft.com/en-us/outlook/add-ins/add-and-remove-attachments-to-an-item-in-a-compose-form

否则,如果您想从读取模式操纵电子邮件。可以有两种选择。

一种是使用Rest API。但是,提出此请求需要满足一些要求。我在桌面上不起作用,但在Web上工作,但如果你想尝试一下,你可以参考这个链接:https://docs.microsoft.com/en-us/outlook/add-ins/use-rest-api

遇到最低要求问题。我发现了一种使用Exchange Web服务请求(EWS)使其工作的方法。它主要使用XML文件发送请求以交换Web服务并返回响应。

但是,我发现我需要获得该电子邮件的MimeContent才能添加到我的CreateItem xml请求中。请查看此链接以获取更多信息。 https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/getitem-operation-email-message

然后,我使用其MimeContent将现有项添加到新电子邮件中。您可以使用以下链接查看:https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-add-attachments-by-using-ews-in-exchange

© www.soinside.com 2019 - 2024. All rights reserved.