首页 > 解决方案 > Outlook Javascript API - 添加以用链接替换正则表达式匹配

问题描述

我想创建一个与 Outlook 2016 兼容的加载项,它只是用超链接替换正则表达式匹配。我的主要问题是我不知道如何访问消息正文。有没有我可以看的示例项目?

这是我的 manifest.xml

        <Rule xsi:type="RuleCollection" Mode="And">
          <Rule xsi:type="ItemIs" ItemType="Message" />
          <Rule xsi:type="ItemHasRegularExpressionMatch" RegExName="OrderNumber" RegExValue="N\d{5}" PropertyName="BodyAsPlaintext"/>
        </Rule>

这是我的 javascript

        export async function run() {
Office.context.mailbox.item.body.getAsync(
    "text",
    { asyncContext: "This is passed to the callback" },
    function callback(result) {
    const r = /N\d{5}/;

        var allMatches = result.value.match(r);

        if (allMatches) {
          JSON.stringify(allMatches, null, 2);
        } else {
          //allMatches = "All matches was null";
        }    
        for (var i = allMatches.length - 1; i >= 0; i--) {
            document.getElementById("item-subject").innerHTML += "<b>Order ID's:</b> <br/>" + "<a href='https://www.test.com.au/admin/order/vieworder?id=" + allMatches[i] + "'>" + allMatches[i] + "</a><br>";
        }

       // document.getElementById("item-subject").innerHTML = "<b>Order ID's:</b> <br/>" + "<a href='https://www.test.com/admin/order/vieworder?id='" + allMatches + ">" + allMatches + "</a>";
    });

主要是工作解决方案

标签: outlookoffice365office-jsoutlook-addin

解决方案


这对您有用吗,您似乎可以像这样访问它:

Office.context.mailbox.item.body.getAsync('text', function bodyCallback(result) {
  console.log('value:', result.value)
});

https://docs.microsoft.com/en-us/javascript/api/outlook/office.body?view=outlook-js-preview

在此处输入图像描述


推荐阅读