Partager via


Sending E-mail Messages in Exchange 2010

Last modified: May 21, 2009

Applies to: Exchange Server 2007 | Exchange Server 2010

You can use Exchange Web Services to send items that have defined recipients.

Example

The following example shows you how to send an item in the Exchange store.

static void SendEmail(ExchangeServiceBinding esb)
{
    // Create the SendItem request.
    SendItemType sit = new SendItemType();
    sit.ItemIds = new BaseItemIdType[1];

    // Create an item ID type and set the message ID and change key.
    ItemIdType itemId = new ItemIdType();

    // Get the ID and change key from the message that you obtained by using FindItem or CreateItem.
    itemId.Id = "AQAtA=";
    itemId.ChangeKey = "CQAAAB";

    sit.ItemIds[0] = itemId;

    // Send the message.
    SendItemResponseType siResponse = esb.SendItem(sit);
    
    // Check the result.
    if (siResponse.ResponseMessages.Items.Length > 0 &&
        siResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
    {
        Console.WriteLine("Message with Id {0} and ChangeKey {1} is sent.", itemId.Id, itemId.ChangeKey);
    }
}

The following XML example shows the XML request message that is sent from the client to the server.

<?xml version="1.0" encoding="utf-8"?>
<SendItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  SaveItemToFolder="false">
  <ItemIds xmlns="https://schemas.microsoft.com/exchange/services/2006/messages">
    <ItemId 
            Id="AQAtA=" 
            ChangeKey="CQAAAB" 
            xmlns="https://schemas.microsoft.com/exchange/services/2006/types" />
  </ItemIds>
</SendItem>

The following XML example shows the XML response message that is sent from the server to the client.

<?xml version="1.0" encoding="utf-8"?>
<SendItemResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ResponseMessages xmlns="https://schemas.microsoft.com/exchange/services/2006/messages">
    <SendItemResponseMessage ResponseClass="Success">
      <ResponseCode>NoError</ResponseCode>
    </SendItemResponseMessage>
  </ResponseMessages>
</SendItemResponse> 

The SOAP messages that are passed between the Exchange Web Services client and server are defined by the XML schema and WSDL files. The XML schema and WSDL files define the contract between the client and server. Proxy class generators create an object-model abstraction of those SOAP messages, which can simplify programming. This code example uses a proxy class library that was generated by MicrosoftVisual Studio 2005. Different proxy class generators create different object models for a given Web service. This proxy class code example is an illustration only. Refer to the proxy class generator documentation for support for proxy classes.

Note

The item identifier and change key have been shortened to preserve readability.

Compiling the Code

For information about compiling the code, see EWS Client Development in Exchange 2010.

Robust Programming

For information about robust programming, see Exchange Web Services Architecture in Exchange 2010.

See Also

Other Resources