order: 3 id: outlook-item-body-add-inline-base64-image name: Add inline Base64-encoded image to message or appointment body (Compose) description: Add an inline Base64-encoded image to the body of a message or appointment being composed. host: OUTLOOK api_set: Mailbox: '1.8' script: content: |- document.getElementById("prepend-image").addEventListener("click", prependImage); document.getElementById("append-image").addEventListener("click", appendImage); const base64String = "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAMAAADVRocKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAnUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAN0S+bUAAAAMdFJOUwAQIDBAUI+fr7/P7yEupu8AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAF8SURBVGhD7dfLdoMwDEVR6Cspzf9/b20QYOthS5Zn0Z2kVdY6O2WULrFYLBaLxd5ur4mDZD14b8ogWS/dtxV+dmx9ysA2QUj9TQRWv5D7HyKwuIW9n0vc8tkpHP0W4BOg3wQ8wtlvA+PC1e8Ao8Ld7wFjQtHvAiNC2e8DdqHqKwCrUPc1gE1AfRVgEXBfB+gF0lcCWoH2tYBOYPpqQCNwfT3QF9i+AegJfN8CtAWhbwJagtS3AbIg9o2AJMh9M5C+SVGBvx6zAfmT0r+Bv8JMwP4kyFPir+cswF5KL3WLv14zAFBCLf56Tw9cparFX4upgaJUtPhrOS1QlY5W+vWTXrGgBFB/b72ev3/0igUdQPppP/nfowfKUUEFcP207y/yxKmgAYQ+PywoAFOfCH3A2MdCFzD3kdADBvq10AGG+pXQBgb7pdAEhvuF0AIc/VtoAK7+JciAs38KIuDugyAC/v4hiMCE/i7IwLRBsh68N2WQjMVisVgs9i5bln8LGScNcCrONQAAAABJRU5ErkJggg=="; function prependImage() { // Insert the Base64-encoded image to the beginning of the body. Office.context.mailbox.item.addFileAttachmentFromBase64Async(base64String, "sample.png", { isInline: true }, (attachmentResult) => { if (attachmentResult.status === Office.AsyncResultStatus.Failed) { console.log(`Failed to attach file: ${attachmentResult.error.message}`); return; } Office.context.mailbox.item.body.prependAsync('', { coercionType: Office.CoercionType.Html }, (prependResult) => { if (prependResult.status === Office.AsyncResultStatus.Failed) { console.log(`Failed to prepend image to body: ${attachmentResult.error.message}`); return; } console.log("Inline Base64-encoded image added to the beginning of the body."); }) }); } function appendImage() { // Get the current body of the message or appointment. Office.context.mailbox.item.body.getAsync(Office.CoercionType.Html, (bodyResult) => { if (bodyResult.status === Office.AsyncResultStatus.Failed) { console.log(`Failed to get body: ${bodyResult.error.message}`); return; } // Add the Base64-encoded image to the end of the body. const options = { isInline: true, asyncContext: bodyResult.value }; Office.context.mailbox.item.addFileAttachmentFromBase64Async(base64String, "sample.png", options, (attachResult) => { if (attachResult.status === Office.AsyncResultStatus.Failed) { console.log(`Failed to attach file: ${attachResult.error.message}`); return; } let body = attachResult.asyncContext; body += ''; Office.context.mailbox.item.body.setAsync(body, { coercionType: Office.CoercionType.Html }, (setResult) => { if (setResult.status === Office.AsyncResultStatus.Failed) { console.log(`Failed to set body: ${setResult.error.message}`); return; } console.log("Inline Base64-encoded image added to the end of the body."); }); }); }); } language: typescript template: content: |-

This sample adds an inline Base64-encoded image to the body of the message or appointment being composed.

Required mode: Compose

Try it out

language: html style: content: |- body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 14px; line-height: 1.5; padding: 10px; } section { margin-bottom: 20px; } h3 { margin-top: 0; margin-bottom: 10px; font-size: 16px; } p { margin: 0 0 10px 0; } button { background-color: #f0f0f0; color: #333333; border: 1px solid #8a8a8a; padding: 8px 16px; font-size: 14px; cursor: pointer; border-radius: 2px; margin-left: 20px; margin-bottom: 5px; min-width: 80px; display: block; } button:hover { background-color: #e0e0e0; } button:active { background-color: #d0d0d0; } input { padding: 8px; margin: 5px 0; border: 1px solid #ccc; border-radius: 2px; font-size: 14px; } .header { text-align: center; background-color: #f3f2f1; padding: 10px; } language: css libraries: |- https://appsforoffice.microsoft.com/lib/1/hosted/office.js https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/types/office-js/index.d.ts