从邮件正文中检索URL的最佳方法

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

以下行是在Mac客户端上使加载项无响应。如果我们删除这一行并直接执行函数someFunction,加载项在mac客户端上工作得非常好。

Office.context.mailbox.item.body.getAsync(“html”,someFunction);

我们使用body.getAsync(),因为我们需要通过处理html和那些包含特定ID的URL来提取邮件正文中的所有URL。

尝试使用下面但没有给出预期的URLS。

var links = Office.context.mailbox.item.getEntities()。urls;

我也在尝试以下方面

Office.initialize = function (reason) {
    $(document).ready(function () {
        app.initialize();
        Office.context.mailbox.item.body.getAsync("html", processHtmlBody);
    });
};

function processHtmlBody(asyncResult) {
    var htmlParser = new DOMParser().parseFromString(asyncResult.value, "text/html");
    var links = htmlParser.getElementsByTagName("a");       
}

是否有更好的替代方法从邮件正文中获取URL。

javascript office365 outlook-addin office-addins office-js
3个回答
1
投票

请注意,getAsync是1.3邮箱要求集的一部分,Outlook for Mac目前不支持:

https://dev.outlook.com/reference/add-ins/tutorial-api-requirement-sets.html

否则使用实体是您唯一的选择,但getElementsByTagName可能效果最佳(如果您有权访问电子邮件正文)。


0
投票

我们使用makeEwsRequestAsync()getEntities().urls尝试了两种替代方案/解决方法,以便从Mac客户端上的邮件主体中检索URL。但两者都没有成功:

  • makeEwsRequestAsync():“没有数据错误”。
  • getEntities().urls:没有给出预期的结果/ URL

因此,对于Mac客户端,我们最终更改了逻辑并添加了条件逻辑,其中不包含任何代码来检索URL。

if(Office.context.requirements.isSetSupported(“mailbox”,1.3)) { //条件代码

}


0
投票

我有同样的问题,我以类似的方式解决了它:

return new Promise((resolve, reject) => {
    mailbox.item.body.getAsync(window.Office.CoercionType.Html, asyncResult => {
        if (asyncResult.status == window.Office.AsyncResultStatus.Succeeded) {
            var $dom = $(asyncResult.value);
            var url = $dom.find('#x_hiddenURL').text();

            resolve(url);
        } else {
            reject(new Error('Failed to load email body'));
        }
   });
});
© www.soinside.com 2019 - 2024. All rights reserved.