2016-03-15 32 views
3

可以在Outlook电子邮件中嵌入图像吗?有了这个代码的前景将插入一个破碎的形象mailBoxItem.body.setSelectedDataAsync如何在Office中插入嵌入式图像-js

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."); 
             } 
            } 
           ) 
         } 

回答

1

它看起来像目前前景并不支持插入<img>标签本身拥有的src元素编码图像64基,需要你有一个改为图片的完整网址。

所以我写了一个服务器端脚本,我在发布base64图像字符串。该脚本将图像保存在服务器上,然后返回URL.Now最后,您可以创建一个<img>标记,并将返回的URL标记为src,并且可以成功嵌入到邮件正文中。

使用的下列代码得到它的工作

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); 
       } 
      }); 
    } 
}); 
+0

谢谢:)我还做了这样的解决方案,但它不接受,我们不能让我们的形象和公众保持不朽的链接。 – Nicu