Javascript 如何使用office js在Outlook中插入嵌入图像

Javascript 如何使用office js在Outlook中插入嵌入图像,javascript,office-js,Javascript,Office Js,是否可以在outlook电子邮件中嵌入图像?使用此代码,outlook将插入损坏的图像mailBoxItem.body.setSelectedDataAsync var linkToImage = '<img src=\"data:image/'+getTemplateExtension(template.templateType).replace('.','')+";base64," + sasLink + '\"/>'; //A

是否可以在outlook电子邮件中嵌入图像?使用此代码,outlook将插入损坏的图像mailBoxItem.body.setSelectedDataAsync

var linkToImage = '<img src=\"data:image/'+getTemplateExtension(template.templateType).replace('.','')+";base64," + sasLink + '\"/>';

                         //Add an image as a link
                        if (mailBoxItem.body.setSelectedDataAsync) {
                            mailBoxItem.body.setSelectedDataAsync(linkToImage, {
                                        asyncContext: null,
                                        coercionType: Office.CoercionType.Html
                                    },
                                    function(asyncResult) {
                                        if (asyncResult.status == "failed") {
                                            showMessage("Action failed with error: " + asyncResult.error.message);
                                        } else {
                                            showMessage("You successfully wrote in the email body. Click Next to learn more.");
                                        }
                                    }
                                )
                        }
var linkToImage='';
//添加图像作为链接
if(mailBoxItem.body.setSelectedDataAsync){
mailBoxItem.body.setSelectedDataAsync(链接到图像{
asyncContext:null,
强制类型:Office.胁迫类型.Html
},
函数(异步结果){
如果(asyncResult.status==“失败”){
showMessage(“操作失败,错误为:+asyncResult.error.message”);
}否则{
showMessage(“您已成功在电子邮件正文中写入。单击“下一步”了解更多信息。”);
}
}
)
}

当前outlook似乎不支持插入
元素,而是要求您拥有图像的完整URL

因此,我编写了一个服务器端脚本,将base64图像字符串发布到该脚本中。脚本将图像保存在服务器上,然后返回URL。现在您终于可以创建一个
,并可以成功地嵌入到消息正文中

使用以下代码使其正常工作

 var imageBase64Data = 'data:image/png;base64,iVBORw...';//truncated the actual base64 data as its too  long
 $.ajax({
     type: 'post',
     url: 'https://metalop.com/Word-Cloud-Generator/image-url-generator.php',
     data: {
         image: imageBase64Data
     },
     error: function(e) {
         console.error(e);
     },
     success: function(response) {
         console.log(response);
         var imageHTML = "<img " +
             "src='" + response + "' img/>";
         console.log(imageHTML);

         //Add an image as a link
         Office.cast.item.toItemCompose(Office.context.mailbox.item).body.setSelectedDataAsync(imageHTML, {
                 coercionType: Office.CoercionType.Html,
             },
             function(asyncResult) {
                 if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                     app.showNotification("Action failed with error: " + asyncResult.error.message);
                 }
             });
     }
 });
var-imageBase64Data='数据:image/png;base64,iVBORw…'//截断了实际的base64数据,因为它太长
$.ajax({
键入:“post”,
网址:'https://metalop.com/Word-Cloud-Generator/image-url-generator.php',
数据:{
图像:imageBase64Data
},
错误:函数(e){
控制台错误(e);
},
成功:功能(响应){
控制台日志(响应);
var imageHTML=“”;
log(imageHTML);
//添加图像作为链接
Office.cast.item.toItemCompose(Office.context.mailbox.item).body.setSelectedDataAsync(imageHTML{
强制类型:Office.胁迫类型.Html,
},
函数(异步结果){
if(asyncResult.status==Office.AsyncResultStatus.Failed){
app.showNotification(“操作失败,错误为:+asyncResult.error.message”);
}
});
}
});
谢谢:)我也提出了这个解决方案,但它不被接受。我们不能公开我们的图片并保持不变的链接。