You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Outlook Mac版Addin API body.getAsync丢失部分样式问题求助

I've run into this exact inconsistency with Outlook for Mac's Office JS API before, especially in older versions like 16.13. Here's a breakdown of what's happening and how you can work around it:

What's Causing the Issue

This is a client-specific bug in Outlook for Mac 16.13. When you insert bullet points via the Outlook UI, the client uses MSO-specific CSS classes (like MsoListParagraph) to render them correctly. However, when you call getAsync with CoercionType.Html, the API strips out these critical classes from the returned HTML. When you pass that sanitized HTML back to setAsync, Outlook can no longer recognize it as a bullet list, so the formatting disappears. This doesn't happen in OWA because the web version handles HTML coercion more consistently.

Workarounds to Try

  • Upgrade Outlook for Mac: This is the most reliable fix. The 16.13 version is several years old, and Microsoft has resolved many API consistency issues in later releases (e.g., 16.50+). Upgrading your client will almost certainly eliminate the bullet point preservation problem.
  • Manually Reconstruct the List Structure: If upgrading isn't an option, you can modify the HTML returned by getAsync to re-add the MSO list classes before calling setAsync. Here's a simple example using regex to wrap bullet items in the required styling:
    // Get the HTML content via getAsync first
    Office.context.mailbox.item.body.getAsync(Office.CoercionType.Html, (result) => {
      if (result.status === Office.AsyncResultStatus.Succeeded) {
        let modifiedHtml = result.value;
        // Replace bullet characters with MSO-styled paragraphs
        modifiedHtml = modifiedHtml.replace(/•(.*?)(<\/p>)/g, "<p class='MsoListParagraph' style='text-indent:0in'>$1</p>");
        
        // Call setAsync with the adjusted HTML
        Office.context.mailbox.item.body.setAsync(modifiedHtml, { coercionType: Office.CoercionType.Html }, (setResult) => {
          // Handle success/failure here
        });
      }
    });
    
    Note: This is a basic regex example—you may need to tweak it to match your specific content structure.
  • Fallback to Text Coercion: If preserving full HTML styling isn't critical, using CoercionType.Text will retain the bullet characters themselves, even if you lose other formatting.

Additional Notes

While the official docs mention that getAsync and setAsync aren't strictly idempotent, this issue is a specific bug in the older Outlook for Mac client rather than a general API limitation. You can report this behavior to Microsoft through their developer feedback channels to help prioritize fixes for legacy versions, though upgrading remains the most practical solution.

内容的提问来源于stack exchange,提问作者BChen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:26:05