Office js 使用“发送时”功能删除HTML电子邮件中的嵌入图像
要删除HTML电子邮件中的嵌入图像,请使用Office js 使用“发送时”功能删除HTML电子邮件中的嵌入图像,office-js,office-addins,outlook-web-addins,Office Js,Office Addins,Outlook Web Addins,要删除HTML电子邮件中的嵌入图像,请使用removeAttachmentAsync()方法(在邮箱API中)。 removeAttachmentAsync()方法成功完成,但其行为不同,如下所示: 网上Outlook(OWA): 发送的电子邮件没有嵌入图像。这和我预期的一样 Windows上的Outlook: 发送的电子邮件中仍有嵌入的图像 在Outlook for Windows中删除嵌入图像的正确方法是什么 第一个代码: const test=async(事件)=>{ 让tim
removeAttachmentAsync()
方法(在邮箱API中)。
removeAttachmentAsync()
方法成功完成,但其行为不同,如下所示:
- 网上Outlook(OWA):
- 发送的电子邮件没有嵌入图像。这和我预期的一样
- Windows上的Outlook:
- 发送的电子邮件中仍有嵌入的图像
const test=async(事件)=>{
让timeout=null;
const item=Office.context.mailbox.item;
item.getAttachmentsAsync((结果)=>{
for(设i=0;i{
clearTimeout(超时);
超时=设置超时(()=>{
事件。已完成({allowEvent:true});
}, 500);
});
}
});
}
更新: 我使用
setAsync()
方法重写了代码。行为发生了变化:
- Windows上的Outlook:
- 发送的电子邮件中嵌入了空白图像
const test=async(事件)=>{
让timeout=null;
const item=Office.context.mailbox.item;
item.getAttachmentsAsync((结果)=>{
for(设i=0;i{
clearTimeout(超时);
超时=设置超时(()=>{
item.body.getAsync(Office.胁迫类型.Html,(result3)=>{
item.body.setAsync(result3.value,{胁迫类型:Office.胁迫类型.Html},()=>{
事件。已完成({allowEvent:true});
});
});
}, 500);
});
}
});
}
解决问题的代码:
const removeImagesFromBody=(事件)=>{
const item=Office.context.mailbox.item;
const type=Office.胁迫类型.Html;
item.body.getAsync(类型,(结果)=>{
让body=result.value;
让我们比赛;
const regex1=new RegExp('v:shapes=“([^”]+)”,'gi');
while((match=regex1.exec(result.value))!==null){
const regex2=新的RegExp(`/gi',);
item.body.setAsync(body,{compressionType:type},()=>{
事件。已完成({allowEvent:true});
});
});
}
调用removeAttachmentAsync()后,需要通过调用body.setAsync()除去对正文中图像的引用
此处记录:感谢您的评论。现在图像通过使用编辑的代码消失。我是否应该手动删除IMG标记以执行与OWA相同的操作?是的,删除IMG
标记是删除正文中图像引用的一部分。感谢您的回复。我根据您提供的信息尝试了各种方法结果,我注意到调整图像的大小会导致邮件中出现v:imagedata
标记,如果我移除IMG
标记,但v:imagedata
标记保留下来,则会生成IMG
标记。因此,我移除了v:imagedata
标记及其相关标记,似乎工作正常很好。另外,我直接删除了IMG
标记,而没有使用removeAttachmentAsync()
方法,这提供了类似的效果。