page_type | products | languages | description | extensions | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
This sample shows you how to get attachments from an Exchange mailbox. |
|
Table of contents
- Summary
- Prerequisites
- Key components of the sample
- Description of the code
- Build and debug
- Troubleshooting
- Questions and comments
- Additional resources
This sample shows you how to get attachments from an Exchange mailbox.
This sample requires the following:
- Visual Studio 2013 with Update 5 or Visual Studio 2015.
- A computer running Exchange 2013 with at least one email account, or a Microsoft 365 account. You can join the Microsoft 365 Developer Program and get a free, renewable 90-day Microsoft 365 E5 subscription.
- Any browser that supports ECMAScript 5.1, HTML5, and CSS3, such as Internet Explorer 9, Chrome 13, Firefox 5, Safari 5.0.6, or a later version of these browsers.
- Familiarity with JavaScript programming and web services.
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.
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.
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.
- Open the solution in Visual Studio.
- Right-click the solution in Solution Explorer. Select Set Startup Projects.
- Select Common Properties, and choose Startup Project.
- Make sure that the Action for AttachmentExampleService project is set to Start.
- Press F5 to build and deploy the sample add-in.
- Connect to an Exchange account by providing the email address and password for an Exchange 2013 server.
- Allow the server to configure the mail account.
- Log on to the email account by entering the account name and password.
- Select a message in the Inbox.
- Wait for the add-in bar to appear over the message.
- In the add-in bar, click AttachmentExample.
- When the mail add-in appears, click the TestAttachments button to send a request to the Exchange server.
- The server will respond with the number of attachments processed for the item. This should equal the number of attachments that the item contains.
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.
- 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].
- More Add-in samples
- Web API: The Official Microsoft ASP.NET Site
- How to: Get attachments from an Exchange server
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.