how to get full path of attachment in office outlook add in? - outlook

Is there any way to get the full path of an outlook add in attachment? Checking the api I only find that it returns the content of the file. I need the path to pass it to a third party library.

Outlook does not store attachments as files. They are stored inside the mailbox and only exist in the context of the parent messages.

As a rule attachments are not saved automatically to the disk until users open them. So, you need to save the attached file to the disk first. Typically attachments are kept in the data store in the Outlook profile.
If you develop a COM add-in you need to save the attached file on the disk by using the Attachment.SaveAsFile method and then pass the file path to a third-party library.
But in case of web add-ins there is no disk APIs due to security reasons (web add-ins are run in a sandboxed environment), so you may pass the attachment content to any web service for processing, see Get attachments of an Outlook item from the server for more information.

Related

Outlook addin - js or api generate email file

I have an outlook addin that I've built using Yeoman. The addin communicates with a server API on my server to combine data from an email with additional data from a database that a user has saved against an email address. This is all working great.
Next I want to store a copy of the email server side, as a file on disk, .msg preferred but I'll take a .eml if thats the only option.
I have 2 options but don't know if either are possible. Either the addin generates the .msg file and posts it to the server API OR the server side API generates the .msg file directly. I have got the server side using the Outlook v2 API and able to pull back the email information when the client passes it the token, id etc. If it could just generate/download a .msg file server side this would be ideal.
As a side note, many of the Microsoft API pages point out the deprecation of the Outlook API in favor of the Graph API, however there are inconsistent links between the pages and it get confusing. I have discovered the token from getCallbackTokenAsync only works with the Outlook API and not Graph, but I cant find out a way to generate a graph compatible token. All the example code from MS uses Office.context.mailbox.restUrl which still gives the Outlook API url and not Graph!
So I guess I'm trying to find out if it's even possible to get/generate a .msg or .eml file either client side using outlook.js or server side using one of the api's. Thank you.
I can get message data both client and server side but cannot get a physical email file.
The Office JavaScript API (OfficeJS) doesn't provide anything for saving messages as msg files (or getting streams). The best what you could do is to use Graph API where you could get the EML file, see Get MIME content of a message for more information.
The server-side code may use the OAuth 2.0 On-Behalf-Of flow (OBO) to request a new access token with permissions to Microsoft Graph. Read more about that in the Authorize to Microsoft Graph with SSO article.
The on-behalf-of (OBO) flow describes the scenario of a web API using an identity other than its own to call another web API. Referred to as delegation in OAuth, the intent is to pass a user's identity and permissions through the request chain.
For the middle-tier service to make authenticated requests to the downstream service, it needs to secure an access token from the Microsoft identity platform. It only uses delegated scopes and not application roles. Roles remain attached to the principal (the user) and never to the application operating on the user's behalf. This occurs to prevent the user gaining permission to resources they shouldn't have access to. See Microsoft identity platform and OAuth 2.0 On-Behalf-Of flow for more information.
Eugene's answer is good. If ultimately you need to get that message to your backend service, using Graph as Eugune described would be the recommended approach. If for whatever reason you are still looking for a capability to access it on client using Office.js, it is not a part of the product. We track Outlook add-in feature requests on our Tech Community Page. Please submit your request there and choose the appropriate label(s). Feature requests on Tech Community are considered, when we go through our planning process. Note there is already a couple of similar ideas there, if you search for "eml" keyword, that you may want to upvote.

Mechanism for determining EWS and REST URL

I have what I hope is a quick question. We are trying to track down why a specific EWS/REST API URL is being returned in OWA by Office Add-ins. Are you able to share the mechanism by which the REST and EWS URLs are determined when running Office.context.mailbox.ewsUrl (or .restUrl). How does the framework determine the right URL to use when in OWA. It doesn't appear to make any extra calls to Exchange. The specific JS in use is outlook-web-16.01.js. It looks like when the Extensions load a service.svc action called GetExtensibilityContext is used and this returns the EWS and REST URLs. However, we were hoping for some more information about what properties in Exchange would impact which URL is used here.
What we are seeing external URLs returned that are only set on four servers where other servers in the environment do not have an external URL set, including the servers where the mailbox in question resides.
Is it designed that if there's an external URL set anywhere in the environment, that is what is returned for the EWS/REST URLs?
Whenever an add-in is launched, it creates an instance of an office object inside the global window object.
Many of the common attributes are stored in that instance of the office itself.
Like ItemId of the item on which the add-in has been opened.
For instance, you can check all the office attributes in the console itself.
Switch the Javascript context to the iframe (since add-ins are loaded inside an iFrame).
Then console log the window.office.context.mailbox object. You'll find all the attributes stored with respect to the item there.
Hope it answers your query.

How to read emails from shared inbox folder on outlook using Graph API?

I have access to the folder called Recalls on Outlook. I want to read all emails in the Inbox subfolder of Recalls using the Graph API. I am using the graph explorer to test the API. On trying https://graph.microsoft.com/v1.0/me/mailFolders, I am only able to see the subfolders under my email but not the ones under Recalls here. My line of thinking is that, since I can see the Recalls folder on my outlook, there must be some way to access it using the Graph API as well. I need help with the right API endpoint or method to access the inbox folder of Recalls. Here is an image to understand the folder structure on Outlook.
Update: I tried using the users API. Even though I have given consent for the needed permissions, I still have an issue with credentials.
If you choose Select permissions from the more actions button (the 3 dots next to the username)in Graph Explorer you can add the permission from the dialogue eg

How to upload outlook attachments to a web service using outlook add-in (Office add-in)?

I have a Outlook Add-in developed using VSTO,that among other features allows a user to select attachments from an email and then upload it to a website. The uploading is done by calling an web-service that resides on the website. I want to convert the VSTO add-in to a Office add-in for making the add-in available on platforms other than Windows. I was searching how this can be achieved. As per the SO post here, Access to the attachment in Outlook web add-in, Outlook Add-in cannot pass the attachments of a selected item directly to the remote service that runs on your server. Instead, the add-in can use the attachments API to send information about the attachments to the remote service. The service can then contact the Exchange server directly to retrieve the attachments.
My clients do not use an Exchange server. If Outlook Add-in cannot pass the attachments directly, I need to download the attachments to a temporary folder on the user's machine and then upload it to the web service from the outlook add-in. Is this possible ? Is there any other alternative to achieve what I want ?
I need to download the attachments to a temporary folder on the user's machine and then upload it to the web service from the outlook add-in. Is this possible ?
This is exactly what I do. Get the path to a folder like Roaming with
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) //C#
download the attachments, encode them, create a json object and send them to your service.
This is the most convenient solution imo
As per this link, Office Add-ins are not supported for Outlook using POP or IMAP accounts.
Requirements for running Office Add ins
I am pasting below the relevant text from the article.
This is unfortunate. This means there is no way to provide customized solutions in Outlook for the following use-cases.
Outlook on Mac or IPad with a POP or an IMAP email account.

How to make Office Web App Server able to edit a document with Cobalt

I am trying to build my own WOPI host using ASP.NET MVC and its WebAPI functions according to this example
https://code.msdn.microsoft.com/office/Building-an-Office-Web-f98650d6
I successfully used that example to connect to my Office Web App Server and I can use that to access files of Excel and PowerPoint in local path and I am able to edit it, but I cannot use it to open word document in editing mode as the Post action handler isn't implemented completely without any response so that it cannot handle any edit request.
In order to add support for editing of Office document, I tried this example with POST request handler based on Cobalt library extracted from Office Web App Server.
https://github.com/marx-yu/WopiHost
With this example I managed to edit ans save all kinds of document with Office Web App Server. However, when I tried to integrate these two together I found that even if I can enter the edit window of Excel and PowerPoint and I can see that Post Requests from Office Web App Server like locking and Cobalt are handled by my WOPI Post API action handler. Those change doesn't take any effect on my local file at all. Moreover, I still cannot edit word document and when I checked the back log of Office Web App Server, I found the error message is Cobalt is not supported while I have already set the SupportsCobalt in CheckFileInfo response to true! Any help is very appreciated!
I think I have exactly what you are looking for. Check out my implementation of the WOPI host. It's an MVC6 app that takes the best from the both examples you are referring to and adds some extra features.

Resources