', { 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