首页 > 解决方案 > Office.context.mailbox.item.body.setAsync 在 Mac Outlook 中为收件人中断图像

问题描述

我们在 Outlook for Mac(版本 16.22.211.0)中看到一个问题,即在邮件正文包含图像时“往返”邮件Context.mailbox.item.body.getAsync正文Context.mailbox.item.body.setAsync。在这种情况下的最简单版本中,我们只是将邮件正文作为 HTML 使用getAsync,然后将完全相同的 HTML 用setAsync.

例如:

function roundtripMailBody() {
    Office.context.mailbox.item.body.getAsync(Office.CoercionType.Html, (result) => {

        if (result.status === Office.AsyncResultStatus.Failed) {
            return;
        }

        const bodyHtml = result.value;

        Office.context.mailbox.item.body.setAsync(bodyHtml, { coercionType: Office.CoercionType.Html });
    });
}

如果邮件正文包含图像(例如,来自签名,或来自用户粘贴图像,或来自用户使用Pictures功能区中的按钮插入图像),调用上述函数将导致图像被破坏当收件人打开邮件时。setAsync有趣的是,在使用;写入正文后,图像并没有立即出现在撰写窗口中。它仅在发送后或关闭撰写窗口并从草稿中重新打开邮件时才会出现损坏。

这是通过以下方式检索的一些示例 HTML body.getAsync

<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=Generator content="Microsoft Word 15 (filtered)">
<style>
<!--
 /* Font Definitions */
 @font-face
    {font-family:"Cambria Math";
    panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
    {font-family:Calibri;
    panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin:0in;
    margin-bottom:.0001pt;
    font-size:12.0pt;
    font-family:"Calibri",sans-serif;}
.MsoChpDefault
    {font-family:"Calibri",sans-serif;}
@page WordSection1
    {size:8.5in 11.0in;
    margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
    {page:WordSection1;}
-->
</style>

</head>

<body lang=EN-US>

<div class=WordSection1>

<p class=MsoNormal><img width=256 height=256 style='width:2.6666in;height:2.6666in'
id="Picture 2"
src="~WRS%7b81702A75-3806-F94F-ACF1-448451D74C09%7d.fld/image001.png"></p>

<p class=MsoNormal>&nbsp;</p>

</div>

</body>

</html>

在通过 将该 HTML 写入正文之后body.setAsync,这是后续调用body.getAsync返回的结果:

<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=Generator content="Microsoft Word 15 (filtered)">
<style>
<!--
 /* Font Definitions */
 @font-face
    {font-family:"Cambria Math";
    panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
    {font-family:Calibri;
    panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin:0in;
    margin-bottom:.0001pt;
    font-size:12.0pt;
    font-family:"Calibri",sans-serif;}
.MsoChpDefault
    {font-family:"Calibri",sans-serif;}
@page WordSection1
    {size:8.5in 11.0in;
    margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
    {page:WordSection1;}
-->
</style>

</head>

<body lang=EN-US>

<div class=WordSection1>

<p class=MsoNormal><img width=256 height=256 style='width:2.6666in;height:2.6666in'
id="Picture 2"
src="~WRS%7b81702A75-3806-F94F-ACF1-448451D74C09%7d.fld/image001.png"
style='height:2.666in;width:2.666in' alt=image001.png></p>

<p class=MsoNormal>&nbsp;</p>

<p class=MsoNormal>&nbsp;</p>

</div>

</body>

</html>

与普通的 HTML 透视图几乎没有什么不同。如果此时关闭撰写窗口,然后从草稿文件夹重新打开,则body.getAsync返回相同的内容,但图像不再呈现。如果发送邮件然后检查其内容(在 OWA 中以便于访问),则正文是:

<div lang="EN-US">
<div class="x_WordSection1">
<p class="x_MsoNormal"><img data-imagetype="External" src="file:////Users/shannon/Library/Containers/com.microsoft.Outlook/Data/Library/Application%20Support/Microsoft/Temp/~WRS%7b81702A75-3806-F94F-ACF1-448451D74C09%7d.fld/image001.png" width="256" height="256" id="x_Picture_x0020_2" alt="image001.png" style="width:2.6666in; height:2.6666in"></p>
<p class="x_MsoNormal">&nbsp;</p>
</div>
</div>

接收端显然是错误的src(指向我机器上不存在的本地文件)。在不破坏邮件正文的情况下重写邮件正文的正确方法是src什么?这个 stackoverflow 问题这个问题似乎与这个问题无关,但我们目前只在 Mac Outlook 中编写时看到这个问题(Windows Outlook 2013、Windows Outlook 2016 和 Outlook Web App 都按预期运行)。我们也没有cid在 Mac Outlook HTML blob 中看到对 a 的任何引用,因此即使我们确实想用srcRest API 中的 base-64 编码替换 ,我们也不知道该怎么做。

这种行为是预期的吗?关于如何解决它的任何想法?

标签: office-jsoutlook-web-addins

解决方案


推荐阅读