Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

OfficeDev/Outlook-Add-in-JavaScript-GetAttachments

Repository files navigation

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.

About

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

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages