无法将邮件移动到 Outlook 插件中的特定文件夹

Not able to move a message to a specific folder in outlook addin

我的 outlook 插件使用 "ReadWriteMailbox" 权限。我正在尝试使用 makeEwsRequestAsync 方法并发送 EWS "MoveItem" 请求以将邮件移动到特定文件夹。但是我收到以下错误,

"The EWS Id is in EwsLegacyId format which is not supported by the Exchange version specified by your request. Please use the ConvertId method to convert the Id from EwsId to EwsLegacyId format."

请求已发送

<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:Header> 
    <RequestServerVersion Version="Exchange2013" /> 
</soap:Header>  
<soap:Body>   
<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">     
    <ToFolderId>
        <t:FolderId Id="AAAbAEJhbGFrcmlzaG5hbl9SQHN5bWFudGVjLmNvbQAuAAAAAACALDzcpfeRQ7ZlsoKB0iVmAQAjK9sGaxZsQpt2dmaMGjhaAADb64+wAAA="  ChangeKey="AQAAABYAAAAjK9sGaxZsQpt2dmaMGjhaAADcIrnw"/> 
    </ToFolderId>     
    <ItemIds>
        <t:ItemId Id="AAMkAGJiNjY2ZTk1LTZkMDEtNGQyYy05M2M2LWMyZmQwMzY1M2JhMQBGAAAAAACALDzcpfeRQ7ZlsoKB0iVmBwArZr3QPuquTIplat84SmYEAEq/mAl5AAAjK9sGaxZsQpt2dmaMGjhaAADb62uqAAA="/>
    </ItemIds>   
</MoveItem> 
</soap:Body>
</soap:Envelope>

收到回复

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="1075" MinorBuildNumber="20" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    </s:Header>
    <s:Body>
        <m:MoveItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
            <m:ResponseMessages>
                <m:MoveItemResponseMessage ResponseClass="Error">
                    <m:MessageText>The EWS Id is in EwsLegacyId format which is not supported by the Exchange version specified by your request. Please use the ConvertId method to convert the Id from EwsId to EwsLegacyId  format.
                    </m:MessageText>
                    <m:ResponseCode>ErrorInvalidIdMalformed</m:ResponseCode>
                    <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
                    <m:Items/>
                </m:MoveItemResponseMessage>
            </m:ResponseMessages>
        </m:MoveItemResponse>
    </s:Body>
</s:Envelope>

我可以使用 MoveItem EWS 操作并将邮件移动到 "Junk Email" 文件夹。但我想将邮件移动到由早期 "CreateFolder" EWS 操作创建的特定文件夹。文件夹的id是"AAAbAEJhbGFrcmlzaG5hbl9SQHN5bWFudGVjLmNvbQAuAAAAAACALDzcpfeRQ7ZlsoKB0iVmAQAjK9sGaxZsQpt2dmaMGjhaAADb64+wAAA="

使用上面的id在"GetFolder"操作正确returns没有。文件夹中的项目。但是我无法使 "MoveItem" 操作正常工作。所有 EWS 操作都通过 "makeEwsRequestAsync" 调用执行。你能帮忙吗?

更新

创建文件夹请求:

<?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:Header> 
    <RequestServerVersion Version="Exchange2013" /> 
</soap:Header>  
<soap:Body>  
    <CreateFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">          
        <ParentFolderId><t:DistinguishedFolderId Id="msgfolderroot"/></ParentFolderId>           <Folders><t:Folder><t:DisplayName>Submissions</t:DisplayName></t:Folder></Folders>    
    </CreateFolder>  
</soap:Body>
</soap:Envelope>

创建文件夹响应:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
 <s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="1075" MinorBuildNumber="21" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<m:CreateFolderResponse 
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
    <m:ResponseMessages>
    <m:CreateFolderResponseMessage ResponseClass="Success">
        <m:ResponseCode>NoError</m:ResponseCode>
        <m:Folders>
        <t:Folder><t:FolderId Id="AAAbAEJhbGFrcmlzaG5hbl9SQHN5bWFudGVjLmNvbQAuAAAAAACALDzcpfeRQ7ZlsoKB0iVmAQAjK9sGaxZsQpt2dmaMGjhaAADek+aFAAA=" ChangeKey="AQAAABYAAAAjK9sGaxZsQpt2dmaMGjhaAADeyyJ9"/>
        </t:Folder>
        </m:Folders>
    </m:CreateFolderResponseMessage>
    </m:ResponseMessages>
</m:CreateFolderResponse>
</s:Body>
</s:Envelope>

移动项目请求:

<?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:Header> <RequestServerVersion Version="Exchange2013" /> </soap:Header>  
<soap:Body>    
<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">     
    <ToFolderId>
        <t:FolderId Id="AAAbAEJhbGFrcmlzaG5hbl9SQHN5bWFudGVjLmNvbQAuAAAAAACALDzcpfeRQ7ZlsoKB0iVmAQAjK9sGaxZsQpt2dmaMGjhaAADek+aFAAA=" ChangeKey="AQAAABYAAAAjK9sGaxZsQpt2dmaMGjhaAADeyyJ9"/> 
    </ToFolderId>    
    <ItemIds>
        <t:ItemId Id="AAMkAGJiNjY2ZTk1LTZkMDEtNGQyYy05M2M2LWMyZmQwMzY1M2JhMQBGAAAAAACALDzcpfeRQ7ZlsoKB0iVmBwArZr3QPuquTIplat84SmYEAEq/mAl5AAAjK9sGaxZsQpt2dmaMGjhaAADdyMHzAAA="/>
    </ItemIds>
</MoveItem>
</soap:Body>
</soap:Envelope>

移动项目响应:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="1075" MinorBuildNumber="21" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<m:MoveItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
    <m:MoveItemResponseMessage ResponseClass="Error">
        <m:MessageText>The EWS Id is in EwsLegacyId format which is not supported by the Exchange version specified by your request. Please use the ConvertId method to convert the Id from EwsId to EwsLegacyId format.
        </m:MessageText>        
        <m:ResponseCode>ErrorInvalidIdMalformed</m:ResponseCode>
        <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
        <m:Items/>
    </m:MoveItemResponseMessage>
</m:ResponseMessages>
</m:MoveItemResponse>
</s:Body>
</s:Envelope>

您对 "CreateFolder" 和 "MoveItem" 的请求更有可能具有不同的“RequestServerVersion". Read more on EWS schema versions in Exchange。EWS Id 格式已更改我相信 "Exchange2007_SP1" 版本。这让我认为您已经使用了 "CreateFolder" 请求的示例,其中包括 "RequestServerVersion" 设置为 "Exchange2007" 并且它将 return 旧文件夹 ID。

编辑:

我没有尝试重现您的 requests/response 序列,而是使用已记录的方式发送以下请求:

创建文件夹的请求看起来像...

<?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:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
    <t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />
</soap:Header>
<soap:Body>
    <CreateFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
        <ParentFolderId>
            <t:DistinguishedFolderId Id="msgfolderroot"/>
        </ParentFolderId>
        <Folders>
            <t:Folder>
                <t:DisplayName>Test Folder1</t:DisplayName>
            </t:Folder>
        </Folders>
    </CreateFolder>
</soap:Body>
</soap:Envelope>

响应是...

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="1084" MinorBuildNumber="21" Version="V2017_04_14" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
    <m:CreateFolderResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <m:ResponseMessages>
            <m:CreateFolderResponseMessage ResponseClass="Success">
                <m:ResponseCode>NoError</m:ResponseCode>
                <m:Folders>
                    <t:Folder>
                        <t:FolderId Id="AQMkADg0ZDZhNWFiLWE0Y2EtNDc4My05MGU1LTY5ZWNiOTQ5MmY5YwAuAAADEgGHnGK1T06Yq8xwQCjiHwEAkUJPW0th2EGwjXYeK6AWSQABv62c1AAAAA==" ChangeKey="AQAAABYAAACRQk9bS2HYQbCNdh4roBZJAAG/8ffU"/>
                    </t:Folder>
                </m:Folders>
            </m:CreateFolderResponseMessage>
        </m:ResponseMessages>
    </m:CreateFolderResponse>
</s:Body>
</s:Envelope>

文件夹创建成功。根据执行 MoveItem 请求的文档,我需要项目的更改密钥。我执行了 GetItem 请求并得到了以下响应 ...

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
    <h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="1084" MinorBuildNumber="21" Version="V2017_04_14" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:GetItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <m:ResponseMessages>
            <m:GetItemResponseMessage ResponseClass="Success">
                <m:ResponseCode>NoError</m:ResponseCode>
                <m:Items>
                    <t:Message>
                        <t:ItemId Id="AQMkADg0ZDZhNWFiLWE0Y2EtNDc4My05MGU1LTY5ZWNiOTQ5MmY5YwBGAAADEgGHnGK1T06Yq8xwQCjiHwcAkUJPW0th2EGwjXYeK6AWSQAAAgEMAAAAkUJPW0th2EGwjXYeK6AWSQABv62YlAAAAA==" ChangeKey="CQAAABYAAACRQk9bS2HYQbCNdh4roBZJAAG/8awE"/>
                    </t:Message>
                </m:Items>
            </m:GetItemResponseMessage>
        </m:ResponseMessages>
    </m:GetItemResponse>
</s:Body>
</s:Envelope>

最后我需要移动项目。以下是我要求移动物品....

<?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:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
    <t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />
</soap:Header>
<soap:Body>
    <MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <ToFolderId>
            <t:FolderId  Id="AQMkADg0ZDZhNWFiLWE0Y2EtNDc4My05MGU1LTY5ZWNiOTQ5MmY5YwAuAAADEgGHnGK1T06Yq8xwQCjiHwEAkUJPW0th2EGwjXYeK6AWSQABv62c1AAAAA=="/>
        </ToFolderId>
        <ItemIds>
            <t:ItemId Id="AQMkADg0ZDZhNWFiLWE0Y2EtNDc4My05MGU1LTY5ZWNiOTQ5MmY5YwBGAAADEgGHnGK1T06Yq8xwQCjiHwcAkUJPW0th2EGwjXYeK6AWSQAAAgEMAAAAkUJPW0th2EGwjXYeK6AWSQABv62YlAAAAA==" ChangeKey="CQAAABYAAACRQk9bS2HYQbCNdh4roBZJAAG/8awE"/>
        </ItemIds>
    </MoveItem>
</soap:Body>
</soap:Envelope>

成功,项目已移至我的新文件夹。

以下是供您继续调试的建议...

  • 看请求是怎么得到itemId的。问题可能在那里。您需要指定相同的“RequestServerVersion”才能获得 ChangeKey.

  • 我建议您对所有 SOAP 请求使用通用函数来包装每个请求主体。在这种情况下,您不会遇到遗留数据的麻烦。 像这样,非常简单的包装器...

        /**
         * Wrap an Exchange Web Services request in a SOAP envelope.
         * @private
         * @param {string} payload request XML.
         * @return {string} Ready to send SOAP EWS request.
         */
        function _wrapSoapEnvelope(payload) {
            var result = '<?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:m="http://schemas.microsoft.com/exchange/services/2006/messages" ' +
                'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
            '<soap:Header>' +
            '<t:RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
            '</soap:Header>' +
            '<soap:Body>' + payload + '</soap:Body>' +
            '</soap:Envelope>';
            return result;
        };
    

在这种情况下,您的请求将非常简单和统一(以下3个请求我已用于您的情况)...

        this.createFolderRequest = function (folderName) {
            var result = '<CreateFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' +
            '<ParentFolderId>' +
            '<t:DistinguishedFolderId Id="msgfolderroot"/>' +
            '</ParentFolderId>' +
            '<Folders>' +
            '<t:Folder>' +
            '<t:DisplayName>' + folderName + '</t:DisplayName>' +
            '</t:Folder>' +
            '</Folders>' +
            '</CreateFolder>';
            return _wrapSoapEnvelope(result);
        };

        this.moveItemRequest = function (folderId, itemId, changeKey) {
            var result = '<MoveItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
            '<ToFolderId>' +
            '<t:FolderId  Id="' + folderId + '"/>' +
            '</ToFolderId>' +
            '<ItemIds>' +
            '<t:ItemId Id="' + itemId + '" ChangeKey="' + changeKey + '"/>' +
            '</ItemIds>' +
            '</MoveItem>';
            return _wrapSoapEnvelope(result);
        };

        this.getChangeKeyRequest = function (itemId) {
            var result = '<GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' +
            '<ItemShape>' +
            '<t:BaseShape>IdOnly</t:BaseShape>' +
            '</ItemShape>' +
            '<ItemIds><t:ItemId Id="' + itemId + '"/></ItemIds>' +
            '</GetItem>';
            return _wrapSoapEnvelope(result);
        };
  • 我建议您检查您的请求,因为它们看起来不同并遵循 Microsoft 原始文档,而不是从其他来源获取的示例。

就是这样。 SO 的目的是 QandA,而不是远程调试,所以你自己解决代码问题。请花点时间调试、清理您的代码并阅读更多有关提供的文档的信息,您将使其正常工作。