Partager via


Performing delegate tasks by using the EWS Managed API 2.0

Last modified: October 13, 2012

Applies to: EWS Managed API | Exchange Server 2007 Service Pack 1 (SP1) | Exchange Server 2010

Note: This content applies to the EWS Managed API 2.0 and earlier versions. For the latest information about the EWS Managed API, see Web services in Exchange.

You can use the Microsoft Exchange Web Services (EWS) Managed API to perform tasks on a delegator's mailbox, such as saving a new item or binding to a folder.

Tip

You must add delegate permissions before you can use delegate access. For information about how to enable delegate access, see Adding delegates by using the EWS Managed API 2.0.

To save a new item to a delegator's account

  1. Create a new Exchange mailbox item, and set the properties on the item. In the following example, an EmailMessage item is created. This step assumes that a valid ExchangeService object is bound to the calling user's account.

    EmailMessage email = new EmailMessage(service);
    email.Subject = "Sample email";
    
  2. Save the item by identifying the delegator's target folder and SMTP address.

    email.Save(new FolderId(WellKnownFolderName.Inbox, "user1@example.com"));
    

The following example shows how to save an e-mail message in another user's mailbox.

static void DelegateAccessCreatingAnItem(ExchangeService service)
{
   // Create an item, in this case an e-mail message.
   EmailMessage email = new EmailMessage(service);
   email.Subject = "Sample email";

   // Save the e-mail message in the delegator's Inbox folder. User1@example.com is the delegator.
   email.Save(new FolderId(WellKnownFolderName.Inbox, "user1@example.com"));
}
Sub DelegateAccessCreatingAnItem(ByVal service As ExchangeService)
    Dim message As New EmailMessage(service)
    message. HYPERLINK "http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Microsoft.Exchange.WebServices:14.0.0.0:31bf3856ad364e35/Microsoft.Exchange.WebServices.Data.Item/property:Subject:String" \o "Property Microsoft.Exchange.WebServices.Data.Item.Subject As String" Subject = "Sample email"
    message. HYPERLINK "http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://Microsoft.Exchange.WebServices:14.0.0.0:31bf3856ad364e35/Microsoft.Exchange.WebServices.Data.Item/Save(Microsoft.Exchange.WebServices.Data.FolderId)" \o "Microsoft.Exchange.WebServices.Data.Item.Save(ByVal FolderId)" Save(New FolderId(WellKnownFolderName.Inbox, "user1@example.com"))
End Sub

To bind to a delegator's folder

  • Create a new folder and bind to the folder in the delegator's mailbox.

    Folder inboxFolder = Folder.Bind(service, new FolderId(WellKnownFolderName.Inbox, "user1@example.com"));
    

Note

This procedure assumes that a valid ExchangeService object is bound to the calling user's account. After a delegate has bound to the delegator's folder, all subsequent items and folders that are accessed through the bound folder will come from the delegator's mailbox.

The following example shows how to bind to a folder in another user's mailbox.

static void DelegateAccessBindingToFolder(ExchangeService service)
{
   // Binds the Inbox folder in the delegator's mailbox. User1@example.com is the delegator.
   Folder inboxFolder = Folder.Bind(service, new FolderId(WellKnownFolderName.Inbox, "user1@example.com"));
}
Sub DelegateAccessBindingToFolder(ByVal service As ExchangeService)
    Dim folder As Folder = Folder.Bind(service, New FolderId(WellKnownFolderName.Inbox, "user1@example.com"))
End Sub

Compiling the code

For information about compiling this code, see Getting started with the EWS Managed API 2.0.

Robust programming

  • Write appropriate error handling code for common search errors.

  • Review the client request XML that is sent to the Exchange server.

  • Review the server response XML that is sent from the Exchange server.

  • Set the service binding as shown in Setting the Exchange service URL by using the EWS Managed API 2.0. Do not hard code URLs because if mailboxes move, they might be serviced by a different Client Access server. If the client cannot connect to the service, retry setting the binding by using the AutodiscoverUrl(String) method.

  • Set the target Exchange Web Services schema version by setting the requestedServerVersion parameter of the ExchangeService constructor. For more information, see Versioning EWS requests by using the EWS Managed API 2.0.

Security

  • Use HTTP with SSL for all communication between client and server.

  • Always validate the server certificate that is used for establishing the SSL connections. For more information, see Validating X509 certificates by using the EWS Managed API 2.0.

  • Do not include user names and passwords in trace files.

  • Verify that Autodiscover lookups that use HTTP GET to find an endpoint always prompt for user confirmation; otherwise, they should be blocked.