Share via

Need a sample for using displayNewMessageForm and addFileAttachmentFromBase64 together

Steve Huff 0 Reputation points
2025-02-09T18:59:11.95+00:00

I'm writing an outlook add-in and need to create a new email with displayNewMessageForm and add an attachment. The problem is the URL to the attachment is protected so I need to download the file and attach it and I've tried using addFileAttachmentFromBase64Async as shown in this example:

https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/add-and-remove-attachments-to-an-item-in-a-compose-form#attach-a-file-or-outlook-item

The problem I'm having is the very first line of the code sample:

const mailItem = Office.context.mailbox.item;

This gets the currently selected mailItem in the mailbox - not the new compose form that was displayed with displayNewMessageForm. Can someone provide a sample that uses displayNewMessageForm then using addFileAttachmentFromBase64Async attaches a file such as a word document to that new compose form?

Microsoft 365 and Office | Development | Other
0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.