mspiess
Jun 29, 2022Copper Contributor
Status:
New
Allow .msg file export through JS add-in API in Outlook-Desktop
I'd like to create an add-in which create a .msg file of an email and sends it to a remote server for archival purposes.
Outlook already can create .msg files through the "Save as..." dialog but this functionality is not exposed to the Office API.
I could access all relevant information through the API and create an .eml file for example (or use EWS/graph-API for that), but I'd prefer to leverage the existing outlook functionality.
I suggest a method "getMsgFileAsync( options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<ArrayBuffer>) => void): void" on the "Office.context.mailbox.item" object.
As far as permissions go, "ItemRead" should suffice.
17 Comments
Sort By
- rajesh2030Copper Contributor
Hi Rich-E
As you have mentioned i have used the same code that is working fine in Read Mode, but my requirement is to save the mail in compose mode also, i am new to Outlook Add in any help will be great for me
- Jim_NeillCopper Contributor
I completely agree. We had that ability in old vba, you would think they wouldn't jsut completely kill functionality.
- TorbenRiisCopper Contributor
From an Enterprise Archive's perspective it would be fantastic to be able to retrieve the original MSG as it is instead of creating a new EML based on data from the API.
- PhilbewanCopper Contributor
It looks like Microsoft has added an Outlook Javascript API preview method for generating a .eml file here:
office.messageread - Jim_NeillCopper Contributor
Huge help, and very kind of you to share. Will give this some testing and hopefully will fit my needs for replacing an old VBA solution.
- Rich-ECopper Contributor
Alrighty Jim_Neill Philbewan here you go:
https://gist.github.com/DevDuck/db4e7e5903d5d3d2d49a238871da4311Call it this way:
try { await getEmailContentAsync({}, async (asyncResult: Office.AsyncResult<string>) => { if (asyncResult.status != Office.AsyncResultStatus.Succeeded) { // handle error return; } let content = asyncResult.value; // upload file // Buffer.from(content, "utf8"); }; } catch (err) { // handle exception }
It's a bit messy but should work. Please let me know if you have any issues with it. I know of one sporadic issue with the Mail app opening the files but Outlook seems to open them fine.
- Rich-ECopper Contributor
just took a look at the code--it's not the prettiest thing right now
give me some time to clean it up before i shove it somewhere!