office-js - 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> </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> </p>
<p class=MsoNormal> </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"> </p>
</div>
</div>
接收端显然是错误的src
(指向我机器上不存在的本地文件)。在不破坏邮件正文的情况下重写邮件正文的正确方法是src
什么?这个 stackoverflow 问题和这个问题似乎与这个问题无关,但我们目前只在 Mac Outlook 中编写时看到这个问题(Windows Outlook 2013、Windows Outlook 2016 和 Outlook Web App 都按预期运行)。我们也没有cid
在 Mac Outlook HTML blob 中看到对 a 的任何引用,因此即使我们确实想用src
Rest API 中的 base-64 编码替换 ,我们也不知道该怎么做。
这种行为是预期的吗?关于如何解决它的任何想法?
解决方案
推荐阅读
- python - Pandas:为列的每个实例创建具有二进制值的数据框
- python - 如何从被调用函数“继续”调用函数中的循环?
- javascript - 如何在 GraphQl JS 中实现带有破折号的枚举
- python - 在 Python(matplotlib)中将水平线插入直方图中?
- mysql - 警告:#4038 参数 1 中 JSON 文本中的语法错误,函数 'st_geomfromgeojson' 在位置 29
- macos-big-sur - 无法在 macOS Big Sur 中执行 Java Robot 类
- python - 读取用户的击键
- java - JUnit - 如何以不同的参数以相同的方法测试重复指令?
- reactjs - 反应本机中的反应导航卸载问题
- java - 一个虚拟盒子上的几个类似的Java程序