This sample has been moved to: Outlook-Add-in-JavaScript-GetAttachments. The description below does not match the new version.

Old Description:

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

Description of the Mail apps for Outlook: Get attachments from an Exchange server sample

This sample shows you how to retrieve attachments from a web service that supports your mail app. 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 app is shown whenever a message or an appointment is the active item. When you select the Process attachments button, the mail app 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.

Prerequisites

This sample requires that you have the following:

  • Visual Studio 2012, with the apps for Office project templates.

  • A computer running cumulative update 1 (CU1) for Exchange 2013 and at least one email account, or an Office 365 developer account.

  • Familiarity with JavaScript programming and web services.

Key components of the sample

The sample solution contains the following files:

  • Attachments project:

    • Attachments.xml - The manifest file for the mail app.

  • The AttachmentService project defines a REST service by using the WCF API. The project was created by using the WebAPI wizard in Visual Studio 2012. 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 app.

    • Models\Attachment.cs - The utility object that helps deserialize the JSON object that is sent by the mail app.

    • Models\AttachmentDetails.cs - The object that represents the details of each attachment. It provides a .NET Framework object that matches the mail apps 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 app.

    • Web.config - Binds the sample service to the web server endpoint.

  • The AttachmentsWeb project contains the UI and JavaScript code for the mail app. The project was created in Visual Studio 2012 and is based on the mail app project template. The following files were modified for this sample:

    • App\Home\Home.html - The HTML user interface for the mail app.

    • App\Home\Home.js - The JavaScript file that handles sending the attachment information to the remote service.

    • Scripts\Office\1.0\ - The mail app API.

Configure the sample

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

Build the sample

Press F5 to build and deploy the sample application. Complete the following tasks to deploy the application:

  1. Connect to an Exchange account by providing the email address and password for an Exchange mailbox.

  2. Allow the server to configure the email account.

Run and test the sample

You run and test the sample in the web browser that is started by Visual Studio when you build and deploy the sample.

Follow these steps to run the sample:

  1. Log on to the email account by entering the account name and password.

  2. Select a message in the Inbox.

  3. Wait for the app bar to appear over the message.

  4. In the app bar, choose Attachments.

  5. When the EWS Request mail app appears, choose the Test attachments button to send a request to the Exchange server.

  6. 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 app for Outlook:

  • The app 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 select F5 to rebuild and deploy the app.

  • Changes to the JavaScript code might not be picked up when you deploy and run the app. If the changes are not picked up, clear the cache on the web browser by selecting Tools - Internet options and choosing the Delete… button. Delete the temporary Internet files and then restart the app.

Related content

Change log

Updated the sample to use the latest API release.