How to: Delay sending an email message by using the EWS Managed API
Published: July 16, 2012

Learn how to delay sending an email message by using the EWS Managed API.
Applies to: Exchange 2013 | Exchange Online | Exchange Server 2007 Service Pack 1 (SP1) | Exchange Server 2010 | Exchange Web Services (EWS) Managed API
Exchange 2013: Send delayed emails programmatically on Exchange servers
To get started using the EWS Managed API to delay sending email messages, complete the following tasks:
Download the EWS Managed API from the Microsoft Download Center, if you haven’t already.
In Visual Studio, add a reference to the EWS Managed API.
Ensure that you have access to an active Exchange Server 2007, Exchange Server 2010, Exchange Server 2013, or Exchange Online mailbox.
Ensure that you have an ExchangeService object that has the correct credentials and the Exchange Web Services (EWS) URL. For information about setting up the ExchangeService object, see Connecting to EWS by using the EWS Managed API.
The following code example shows how to delay sending an email message. To use this code example, update the SMTP address in the To: recipients line.
// Delays the time that an email message is sent. static void DelaySendEmail(ExchangeService service) { EmailMessage message = new EmailMessage(service); // Identify the extended properties that are used to set the time when the email message is sent. ExtendedPropertyDefinition PR_DEFERRED_SEND_TIME = new ExtendedPropertyDefinition(16367, MapiPropertyType.SystemTime); // Identify when the email message will be sent and delivered. The email message is delivered three minutes after the // next line executes. string sendTime = DateTime.Now.AddMinutes(2).ToUniversalTime().ToString(); // Set the extended properties with the dateTime for when the mail will be delivered. message.SetExtendedProperty(PR_DEFERRED_SEND_TIME, sendTime); message.ToRecipients.Add("tadams@contoso.com"); message.Subject = "Test subject"; StringBuilder str = new StringBuilder(); str.AppendLine("Client submitted at: " + DateTime.Now.ToString()); Console.WriteLine("Client submitted at: " + DateTime.Now.ToString()); str.AppendLine("To be sent at: " + sendTime); Console.WriteLine("To be sent at: " + sendTime); message.Body = str.ToString(); message.SendAndSaveCopy(); }
This code example first creates an email message object, and then it creates an extended property definition to specify the MAPI property that is used to set the deferred send time. For more information about this property, see PidTagDeferredSendTime Canonical Property. The deferred send time information is set on the email message along with an email recipient, a subject, and the email message body. The message.SendAndSaveCopy() line results in a call to the service. If the call is successful, the email message will be available in the caller’s Outbox folder. After the email message is sent, a copy of the message will be created in the Sent Items folder.
This article shows how to delay sending an email message to a single recipient. Next, you might want to explore other ways that you can use the EWS Managed API to work with email messages. See the following articles:
Date | Description |
|---|---|
July 16, 2012 | Initial publication |