Code Monkey home page Code Monkey logo

outlook-add-in-javascript-getattachments's Introduction

page_type products languages description extensions
sample
office-outlook
office-365
javascript
This sample shows you how to get attachments from an Exchange mailbox.
contentType technologies createdDate
samples
Add-ins
8/11/2015 1:48:02 PM

Outlook add-in: Get attachments from an Exchange server

Table of contents

Summary

This sample shows you how to get attachments from an Exchange mailbox.

Prerequisites

This sample requires the following:

Key components of the sample

The sample solution contains the following files:

  • AttachmentExampleManifest.xml: The manifest file for the Outlook add-in.
  • AppRead\Home\Home.html: The HTML user interface for the mail add-in for Outlook.
  • AppRead\Home\Home.js: The JavaScript file that handles sending the attachment information to the remote Attachment service included with this sample.

The AttachmentService project defines a REST service by using the WCF API. The project contains the following files:

  • Controllers\AttachmentServiceController.cs: The service object that provides the business logic for the sample service.
  • Models\ServiceRequest: The object that represents a web request. The contents of the object are created from a JSON request object sent from your mail add-in.
  • Models\Attachment.cs: The utility object that helps deserialize the JSON object that is sent by the mail add-in.
  • Models\AttachmentDetails.cs: The object that represents the details of each attachment. It provides a .NET Framework object that matches the mail add-in's AttachmentDetails object.
  • Models\ServiceResponse: The object that represents a response from the web service. The contents of the object are serialized to a JSON object when they are sent back to the mail add-in.
  • Web.config: Binds the sample service to the web server endpoint.

Description of the code

This sample shows you how to retrieve attachments from a web service that supports your mail add-in. For example, you can create a service that uploads photos to a sharing site, or a service that stores documents into a repository. The service gets the attachments directly from the Exchange server, and doesn't require the client to perform extra processing to get the attachment and then send it along to the service.

The sample has two parts. The first part, the mail app, runs in the email client. The mail add-in is shown whenever a message or an appointment is the active item. When you select the Test attachments button, the mail add-in sends details about the attachment to the web service that processes the request. The service uses the following steps to process attachments:

  • Sends a GetAttachment operation request to the Exchange server that hosts the mailbox. The server responds by sending the attachment to the service. In this sample, the service simply writes the XML from the server to trace output.
  • Returns the number of attachments processed to the mail app.

Build and debug

Note: The mail add-in will be activated on any email message in the user's Inbox that has one or more attachments. You can make it easier to test the add-in by sending one or more email messages to your test account before you run the sample add-in.

  1. Open the solution in Visual Studio.
  2. Right-click the solution in Solution Explorer. Select Set Startup Projects.
  3. Select Common Properties, and choose Startup Project.
  4. Make sure that the Action for AttachmentExampleService project is set to Start.
  5. Press F5 to build and deploy the sample add-in.
  6. Connect to an Exchange account by providing the email address and password for an Exchange 2013 server.
  7. Allow the server to configure the mail account.
  8. Log on to the email account by entering the account name and password.
  9. Select a message in the Inbox.
  10. Wait for the add-in bar to appear over the message.
  11. In the add-in bar, click AttachmentExample.
  12. When the mail add-in appears, click the TestAttachments button to send a request to the Exchange server.
  13. The server will respond with the number of attachments processed for the item. This should equal the number of attachments that the item contains.

Troubleshooting

The following are common errors that can occur when you use Outlook Web App to test a mail add-in for Outlook:

  • The add-in bar does not appear when a message is selected. If this occurs, restart the application by selecting Debug – Stop Debugging in the Visual Studio window, then press F5 to rebuild and deploy the add-in.
  • Changes to the JavaScript code may not be picked up when you deploy and run the add-in. If the changes are not picked up, clear the cache on the web browser by selecting Tools – Internet options and clicking the Delete… button. Delete the temporary Internet files and then restart the add-in.

Questions and comments

  • If you have any trouble running this sample, please log an issue.
  • Questions about Office Add-in development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [office-addins].

Additional resources

Copyright

Copyright (c) 2015 Microsoft. All rights reserved.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

outlook-add-in-javascript-getattachments's People

Contributors

davidchesnut avatar dependabot[bot] avatar dkontyko avatar eloekset avatar jamescro avatar lindalu-msft avatar mimisasouvanh avatar nokafor avatar o365devx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

outlook-add-in-javascript-getattachments's Issues

mailbox.item.attachments[i].$0_0 is undefined

The attachment object may have changed since this project was created. When I clone and run this in the browser today, I get an error when handling JSON for the attachment object.

I found that it happens because the $0_0 property is undefined, and the properties needed are available under the _data$p$0 property. I've modified the code and will send a PR.
attachmentexampleerror_1

OWA and iFrame

Is there a way to update the web.config of an Outlook for web add-in to prevent the "... cannot be displayed in a frame" error?

Thanks

Help with fetching attachments

I am trying to develop an Add-in for Outlook, for that I have cloned this repo and have followed the instructions mentioned there.

My question is, when my add-in makes a request to https://localhost:44320/api/AttachmentService, it sends back a response with the following content:

{ "isError": false, "message": null, "attachmentsProcessed": 2, "attachmentNames": [ "avatar-1606916_960_720.png", "HnVmB0-k.jpg" ] }

But it does not tell me the URL of my attachment using which i can view the attachment.

Please help me

Thanks in advance

Continued support of authentication method

I was wondering if you could please tell me if the authentication used in this example is classed as basic and potentially should be replaced. I am currently developing an Outlook add-in that needs to save the emails and attachments of clients to our database. I have read in a recent blog post from Microsoft that basic authentication would be potentially stopped:

https://techcommunity.microsoft.com/t5/exchange-team-blog/improving-security-together/ba-p/805892

Is the methodology in this repository classed as basic, thus needs updating or can I still use it for the foreseeable future? Any advice regarding this topic would be greatly appreciate

not working in mobile outlook app

have developed an Outlook web add-in which can be used in Outlook native client, mobile app and outlook web to upload files to SharePoint online document library.
1. In the add-in, JavaScript calls a new Office.js API getAccessTokenAsync. This tells the Office host application to obtain an access token to the add-in. (Hereafter, this is called the access token because it is replaced with a second token later in the process.For an example of a decoded bootstrap access token.
2. If the user is not signed in, the Office host application opens a pop-up window for the user to sign in.
3. If this is the first time the current user has used your add-in, he or she is prompted to consent.
4. The Office host application requests the access token from the Azure AD v2.0 endpoint for the current user.
5. Azure AD sends the bootstrap token to the Office host application.
6. The Office host application sends the access token to the add-in as part of the result object returned by the getAccessTokenAsync call.
7. JavaScript in the add-in makes an HTTP request to a web API that is hosted at the same fully-qualified domain as the add-in, and it includes the access token as authorization proof.
8. Server-side code validates the incoming access token.
9. Server-side code uses the “on behalf of” flow to obtain an access token.
10. Azure AD returns the access token to the add-in.
11. Server-side code caches the access token.
12. Server-side code makes requests to exchange server to get attachment and upload attachment into SharePoint.
13. SharePoint REST API returns data to the add-in, which can pass it on to the add-in’s UI.
14. When the access token expires, the server-side code can use its refresh token to get a new access token.

This add-in is working in desktop and web outlook but is failing inconsistently in mobile devices using native outlook app.
 
In mobile device: it is working randomly for some accounts whereas the same code is not working for other accounts irrespective of the device.
 
We have verified for outlook versions, devices, account permissions level and do not see any issues.
While debugging we suspected that the problem might be processing documents from EWS server. In mobile outlook app the attachment token and ID values are different from desktop/web client for the same code. 

Code links – 
https://docs.microsoft.com/en-us/outlook/add-ins/get-attachments-of-an-outlook-item  

We are receiving the error in below snippet of code that is referenced from the above mentioned links.

ExchangeService service = new ExchangeService(); 
service.Credentials = new OAuthCredentials(request.attachmentToken); 
service.Url = new Uri(request.ewsUrl); 

var getAttachmentsResponse = exchangeService.GetAttachments(attachmentIds.ToArray(),
                             null,
                             new PropertySet(BasePropertySet.FirstClassProperties,
                             ItemSchema.MimeContent));

getAttachmentsResponse.OverallResult                  returning  ERROR in mobile for particular users


Need help to resolve this issue 


Thanks & Regards
Girish Kumar MS
[email protected]

Reading attachments metadata in compose mode

Hello,
The example is showing information of attachments in read only mode. Do we have solution for reading attachments metadata in compose mode? I would like to show the attachment metadata like title, id and size in the add-in.

This add-in is working in desktop and web outlook but is failing inconsistently in mobile devices using native outlook app.

This add-in is working in desktop and web outlook but is failing inconsistently in mobile devices using native outlook app.

In mobile device: it is working randomly for some accounts whereas the same code is not working for other accounts irrespective of the device.

We have verified for outlook versions, devices, account permissions level and do not see any issues.
While debugging we suspected that the problem might be processing documents from EWS server. In mobile outlook app the attachment token and ID values are different from desktop/web client for the same code.

Code links –
https://docs.microsoft.com/en-us/outlook/add-ins/get-attachments-of-an-outlook-item

We are receiving the error in below snippet of code that is referenced from the above mentioned links.

ExchangeService service = new ExchangeService();
service.Credentials = new OAuthCredentials(request.attachmentToken);
service.Url = new Uri(request.ewsUrl);

var getAttachmentsResponse = exchangeService.GetAttachments(attachmentIds.ToArray(),
null,
new PropertySet(BasePropertySet.FirstClassProperties,
ItemSchema.MimeContent));

getAttachmentsResponse.OverallResult returning ERROR in mobile for particular users

Need help to resolve this issue

GetAttachments using REST API

Recently our Outlook Addin had a validation comment about not being able to support Gmail for Mac because we implemented getting attachments using EWS as per this example. However, looking at this page we see

You cannot use Exchange Web Services (EWS) to access items in the Gmail mailbox. This means that you cannot use makeEwsRequestAsync or use an EWS callback token from getCallbackTokenAsync to make EWS calls directly. Instead, you can get the same type of access to the items in the mailbox by using the Outlook REST APIs.

Now, call this wishful thinking but our developers would totally love to see an example (similar to this one) for getting attachments using REST API. Pretty please! 😃 🙏🏽

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.