22 out of 35 rated this helpful - Rate this topic

Get started with mail apps for Outlook 2013 and EWS in Exchange 2013

Exchange Server 2013

Published: July 16, 2012

Learn how to use EWS from your mail app for Outlook and Outlook Web App.

Applies to:  Exchange 2013 | Exchange Online | Outlook 2013 | Outlook Web App | apps for Office 

Note Note

Unless otherwise specified, references to "Outlook" apply to the Outlook 2013 rich client and Outlook Web App for Exchange Server 2013.

Mail apps provide a new way for you to add information to Outlook. Mail apps use standard web technologies to extend Outlook.

Your mail app can interact with an Exchange Server 2013 server to provide a rich experience to your users. To make it easier for you to use EWS from your app, the mail apps for Outlook JavaScript API provides a method for making asynchronous requests to EWS.

Visual Studio 2012 provides built-in tools for building and deploying mail apps. You don't have to use Visual Studio, however. You can use a simple text editor to create a mail app for Outlook.

If you’re using Visual Studio, you will need the following:

  • Visual Studio 2012

  • Apps for Office project templates

  • Exchange Server 2013

If you’re using a text editor, you'll need access to the following:

  • A server running Exchange 2013.

  • A web server that can be reached by the Exchange server and that is configured to send and receive HTTPS.

  • A web browser, such as Internet Explorer 9, that can display HTML5 documents.

  • A directory for the manifest file that you can access from the computer where you’re running your web browser.

For an example that shows you how to create a mail app by using a text editor, see How to: Create your first mail app for Outlook by using a text editor.

Mail apps for Outlook are designed to take advantage of your web programming skills to create a new experience for your customers. You can use standard web technologies to create apps that interact with email messages and appointments that display information from the Exchange server, or that can integrate the email client with information from any web service. To create a mail app that uses EWS, you'll need to be familiar with the technologies listed in the following table.

Table 1. Core concepts for mail apps and EWS

Technology

Description

XML

You'll use XML to create and parse the EWS requests and responses.

JavaScript

The logic for your mail app is written using a JavaScript API. If you have experience creating JavaScript code for the web, you'll be able to quickly create apps.

HTML5

The user interface for your mail app is written in HTML5. You can use your web display skills to create an attractive UI.

To help you get started using EWS with your mail apps, the following is a simple example that requests the subject of the current message from the Exchange server. You can build on the information that you learn here to create your own mail app that works with EWS.

Step 1: Create a mail app for Outlook by using Visual Studio

Follow these steps to create a mail app for Outlook project in Visual Studio:

  1. Choose New Project… from the Start page.

  2. In the Template list, choose Office SharePoint, and then choose Apps.

  3. Choose the App for Office template. Name the project EWSApp, and then choose the OK button.

  4. In the Create App for Office dialog, choose Mail app in:, then choose Appointment to clear the check box. Choose the Finish button to create the mail app.

Step 2: Add the JavaScript code for the mail app

Copy the following code into the EWSApp.js file.

function getSoapEnvelope(request) {
    // Wrap an EWS request in a SOAP envelope.
    var result =

    '<?xml version="1.0" encoding="utf-8"?>' +
    '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
    '               xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
    '               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
    '               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
    '  <soap:Header>' +
    '    <RequestServerVersion xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
    '  </soap:Header>' +
    '  <soap:Body>' +

    request +

    '  </soap:Body>' +
    '</soap:Envelope>';

    return result;
}

function getSubjectRequest(id) {
    // Return a GetItem EWS operation request for the subject of the specified item. 
    var result =

 '    <GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' +
 '      <ItemShape>' +
 '        <t:BaseShape>IdOnly</t:BaseShape>' +
 '        <t:AdditionalProperties>' +
 '            <t:FieldURI FieldURI="item:Subject"/>' +
 '        </t:AdditionalProperties>' +
 '      </ItemShape>' +
 '      <ItemIds><t:ItemId Id="' + id + '"/></ItemIds>' +
 '    </GetItem>';

    return result;
}

// Send an EWS request for the message's subject.
function sendRequest() {
    // Create a local variable that contains the mailbox.
    var mailbox = Office.context.mailbox;
    var request = getSubjectRequest(mailbox.item.itemId);
    var envelope = getSoapEnvelope(request);

    mailbox.makeEwsRequestAsync(envelope, callback);
}

// Function called when the EWS request is complete.
function callback(asyncResult) {
    var response = asyncResult.value;
    var context = asyncResult.context;

    // Process the returned response here.
    var responseSpan = document.getElementById("response");
    responseSpan.innerText = response;
}

Step 3: Add the UI for the mail app

Replace "Mail App" in the EWSApp.html file with the following HTML.

<h1>EWS request</h1>
<input type="button" value="Make EWS request" onclick="sendRequest()" />
<div style="overflow:scroll; height: 100px;">
   <span id="response" />
</div>

Step 4: Change the manifest.xml file to enable web service requests

To help improve security, your app will not be able to call EWS until you change the permissions for the app. To change the permissions, follow these steps in Visual Studio:

  1. Open the EWSApp project in the Solution Explorer.

  2. Choose EWSApp.xml to open the manifest file editor.

  3. From the Permissions list, choose ReadWriteMailbox.

  4. Save the changes and close the editor.

Step 5: Deploy and run the mail app

You'll need to deploy the HTML and JavaScript for your mail app and install the manifest file into Outlook or Outlook Web App to run the app. Follow these steps to make your mail app visible in Outlook Web App:

  1. Choose the F5 key to start to deploy and run the mail app.

  2. Connect to an Exchange account by providing the email address and password on an Exchange 2013 server.

  3. Allow the server to configure the email account.

  4. Lon on to the email account by entering the account name and password.

  5. Select a message in the Inbox.

  6. Wait for the App bar to appear over the message.

  7. In the app bar, choose EWSApp.

  8. When the EWSApp mail app appears, select the Make EWS Request button to request the subject of the current email message from the Exchange server.

The response XML that is returned by the request is displayed in the UI so that you can examine the response.

More ideas for mail apps

This simple example provides a glimpse of what you can do with EWS and mail apps. For additional examples, see the articles listed in the following table.

Table 2. Basic tasks for working with EWS and mail apps

Article

Description

How to: Activate a mail app in Outlook for a specific message class

Shows you how to open your mail app on messages, appointments, or both.

How to: Extract entity strings from an item in a mail app for Outlook

Shows you how to pull entities, such as addresses, URLs, or phone numbers out of an item.

Read the articles listed in the following table to learn more about EWS and mail apps.

Table 3. Advanced EWS and mail app concepts

Article

Description

Build apps for Office

Describes apps for Office and the features that mail apps for Outlook shares with apps for other Office products.

Mail apps for Outlook

Describes the apps for Office features that are unique to mail apps.

Mailbox.makeEwsRequestAsync method (apps for Office)

Reference documentation for the API method that you use to make EWS requests for a mail app for Outlook and Outlook Web App.

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.