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

1

8

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.

Bruckner answered 15/3, 2016 at 12:11 Comment(2)
are you trying to insert an inline image, is that it?Eury
Yes, the main goal would be to have images inserted for signatures.Bruckner
E
5

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

}
});
Eury answered 16/3, 2016 at 19:10 Comment(1)
Thank you for the code sample. I tried it in outlook and it does not seem to work. What I see to have a cid reference working you have to attach the content as base64.Bruckner

© 2022 - 2024 — McMap. All rights reserved.