1

I am developing an Outlook Web Access Add-In in which I want to access all the data of an email including sender address, recipient address, subject and sent date etc. I also want to download the entire message file. I have found one Outlook Web REST API but don't know how to use it.

Can anyone explain how to use this API to retrieve the entire MIME message and provide an example?

markdon
  • 784
  • 8
  • 19
Madi
  • 15
  • 1
  • 5

2 Answers2

4

I guess you want to get the current email in MIME format (aka *.eml file type). If so, see the answer.

1. Exchange Web Services (EWS). Prior 2019 year

You have to use Exchange Web Services (EWS) and there are two ways:

  1. Do it in JavaScript via makeEwsRequestAsync() method by setting IncludeMimeContent property in the request and process content of the MimeContent tag of the response (it's base64, so you may need to decode).

    But it doesn't work on iOS/Android (link) and the email size limit for JavaScript APIs is 1 MB (see all limitations of the JavaScript API), so the implementation of fetching and decoding the email must run on the back-end (which may be an unnecessary load for the server). Hence you may forget option #1 and start reading the next option.

  2. Send EWS request and process the response on the back-end. But for that you need to get a callback token (for authentication from your back-end), item ID of the email and the EWS url (see this post on how to get them in the add-in).

Having said that, there are said news. Since July 2018 Microsoft issues only security updates for EWS (see the official statement). They phase it out in favour of Microsoft Graph, the new gateway to Office data, which so far does NOT support export of email in the EML format. The feature is promised in beta by the end of 2018.

2. Microsoft Graph. Starting from 2019 year

EWS is dead and Microsoft Graph is the way to go. The Microsoft folks promised to expose the entire email MIME stream in Outlook Mail REST API (should be in beta by now). So keep an eye on Outlook mail REST API.

Note: MS Graph works only with Exchange Online (Office 365 in the cloud) or on Exchange on-premises in a hybrid deployment (requires at least Exchange 2016 Cumulative Update 3 (CU3) on-premises server integrated with Office 365).

Community
  • 1
  • 1
Alex Klaus
  • 8,168
  • 8
  • 71
  • 87
3

1. To get the message details you can use the javascript APIs available in office.js. Refer the link for details on individual APIs that are available on an item:

https://dev.office.com/reference/add-ins/outlook/1.5/Office.context.mailbox.item?product=outlook&version=v1.5

2. To get the entire message file. GetMessage API does not provide you with a .msg file but it will fetch you all the properties of the message, you can use this to get extra details about the message which are not provided by the javascript APIs directly.

3. There is a way to get a .eml file using the following two steps:

Step1: Get a EWS callback token using the JS API getCallbackTokenAsync([options], callback). Refer link:

https://dev.office.com/reference/add-ins/outlook/1.5/Office.context.mailbox?product=outlook&version=v1.5

Step2: With this token from your server make an EWS request to get the item with IncludeMimeContent set to true and save the response as a .eml file. Refer link:

https://msdn.microsoft.com/en-us/library/office/aa566013(v=exchg.150).aspx

  • 2
    Thank u for the answer .could u please share any example how to save response as a .eml file – Madi Jun 20 '17 at 08:23
  • Actually i dont understand how to take start in which file i have to write this code .do u have any example for VS2017 . – Madi Jun 20 '17 at 10:54
  • Option one of using the Office-js API is very reasonable as long as you don't actually need the _actual_ original full MIME message. There is enough information provided through this API to build a new MIME message and write it to a .eml file. It's just going to be missing much of the information that a user would never see. – markdon Jan 31 '20 at 01:34
  • How to send the EWS request with token from the 'getCallbackTokenAsync' to the on-prem server EWS end-point? Is it with the Authorization Bearer header, or other approach? – Brian Clink Feb 04 '20 at 16:06
  • We got it to work with the token in the Bearer going to the on-prem EWS URL. Thanks. – Brian Clink Feb 04 '20 at 17:01
  • 1
    The links on dev.outlook.com are dead. :-/ – greg-e Nov 26 '20 at 07:54