Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add images as multipart/related MIME object to Outlook with Office Js Addin

I'm using addFileAttachmentAsync to add an image as an attachment to an email in outlook 2016. Is there a way to specify attachment options? I saw that there is an AttachmentDetail type, can I somehow use this one to specify additional options? My goal is to embed images using multipart/related MIME object.

like image 699
Atti Avatar asked Mar 15 '16 12:03

Atti


1 Answers

Inline images don't have great support in the platform right now. We're working on improving this. In the meantime, you can either include <img> tag loading an image from the web, or you can use this code. In OWA, the sender will see an attachment appear in the attachment well and in Outlook, the image won't render for the sender at all. But in both cases the recipient will see a proper inline image.

Office.context.mailbox.item.addFileAttachmentAsync(
"http://smartbuildings.unh.edu/wp-content/uploads/2015/06/Winter-Tiger-Wild-Cat-Images-1024x576.jpg",
"Winter-Tiger-Wild-Cat-Images-1024x576.jpg",
{asyncContext: null},
function (asyncResult) 
 {
  if (asyncResult.status == "failed") {
    //showMessage("Action failed with error: " + asyncResult.error.message);
  }
  else
{ 
Office.context.mailbox.item.body.setSelectedDataAsync(
                        "<img src='cid:Winter-Tiger-Wild-Cat-Images-1024x576.jpg'>",
                        { coercionType: Office.CoercionType.Html, 
                        asyncContext: { var3: 1, var4: 2 } },
                        function (asyncResult) {
                            if (asyncResult.status == 
                                Office.AsyncResultStatus.Failed){
                                showMessage(asyncResult.error.message);
                            }
                            else {
                                // Successfully set data in item body.
                                // Do whatever appropriate for your scenario,
                                // using the arguments var3 and var4 as applicable.
                            }
                        });

}
});
like image 64
AndrewS Avatar answered Nov 14 '22 23:11

AndrewS