1

I want to create an outlook web add-in ,in which I want .eml and and .txt of the email message and its attachment list? I am confused between EWS , Outlook RestAPI and MS Graph API to build it. I tried using EWS , but it had two issues:

  1. where to get these credentials ,(an example would be helpful)

    service = new ExchangeService { Credentials = new WebCredentials(OutlookEmailId, Password)

                     };
    
  2. EWS are obsolete now.

So what is the right way of getting the email message content ? Could anyone please explain the steps in plain english. Also, any example would be a big help to start.

I am newbie in these integration and OAUTH concepts, please suggest. I want to put my efforts in right direction.

Asmi
  • 157
  • 1
  • 1
  • 14

1 Answers1

2
  1. EWS isn't obsolete (and won't be for some time) it just basic Auth has been deprecated which should be an issue in Modern Addin.

You can get the Mime content of a Message (which is basically what is the content of an EML file) using the Graph eg https://learn.microsoft.com/en-us/graph/outlook-get-mime-message. To use that in a Addin you need to use make use of SSO see https://github.com/OfficeDev/Outlook-Add-in-SSO which has a pretty comprehensive sample you just need to change some of the REST call to do what you want.

There is working sample of using EWS in a Addin on https://gsexdev.blogspot.com/2019/05/outlook-addin-for-exporting-email-to.html (this has the 1MB limitation)

If you trying to go past 1MB there a few options to take with EWS use the answer in How can I retrieve the full MIME message from an Microsoft Outlook Add-In?.

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • Thanks for mentioning the link Glen. It's perfect! – Outlook Add-ins Team - MSFT Apr 06 '21 at 05:31
  • Thanks for suggesting the solution. I am using this reference [https://github.com/OfficeDev/Outlook-Add-in-SSO] https://github.com/OfficeDev/Outlook-Add-in-SSO . I have few queries : 1) in what scenarios SSO Tokens are not available? and we need to have another method to authenticate users . 2)In the refernce project Token is acquired by calling getCallbackTokenAsync, to use Outlook Rest API to get email data., but It seems from Microsoft documentation, Outlook RestAPI is deprecated. Please advice. – Asmi Apr 28 '21 at 16:13
  • Good question i would suggest creating an Issue on the Github repository (MSFT)need to update the code and guidance for the Outlook Endpoint around this(I asked the same question recently as its confusing especially in regards to the OnPrem/Hybrid endpoint). In terms of getCallbackTokenAsync in that example you could get rid of that and include the correct scopes in the Graph token and then use the Graph instead of the Outlook Endpoint. – Glen Scales Apr 29 '21 at 00:05
  • Thanks for responding Glen! Could you please suggest what should be the next steps if I can not get SSO token for authenticating user, what should be my approach in else part? – Asmi Apr 29 '21 at 11:55
  • @Glen I am slightly puzzled among these approaches Outlook Rest API, Exchange web services , Identity exchange token or authenticate user without SSO? My purpose is to get Mime content of email and its attachment from outlook in my outlook web addin. – Asmi Apr 29 '21 at 11:59
  • > if I can not get SSO token for authenticating user, - Can you expand on this what scenarios is this happening, you could always present a user authentication dialogue which is messy but SSO should work is most environments. – Glen Scales Apr 29 '21 at 23:50
  • EWS is the easiest method as it will work anywhere (eg OnPrem/Clound) but you have the 1MB limitation, getCallbackTokenAsync and passing off eg https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/get-attachments-of-an-outlook-item using EWS should also work those token are valid for 5 minutes and should be good to use in a GetItem call that would return the MimeContent which would allow you to work around the 1MB limit. It requires hosted code outside of you addin to essentially do the work. – Glen Scales Apr 30 '21 at 00:01