HOWTO: Use CDO to Set the Message Delivery Options

ID: Q195381

The information in this article applies to:

SUMMARY

This article demonstrates how to create a message using Collaboration Data Objects (CDO) and then sets the deferred delivery time and message expiration time settings. This can be useful for sending time sensitive messages programmatically.

MORE INFORMATION

This sample creates a message and sets the message to be sent at 10:00 AM. It also sets the message to expire at 6:00 PM.

1. Create a new Visual Basic project and add a reference to the Microsoft

   CDO 1.21 Library.

2. Add a command button to the form and set the caption to "Set send
   options".

3. In the Click event of the "Set send options" command button, add the
   following code:

      Dim oSession As MAPI.Session
      Dim oOutbox As Folder
      Dim omessage As Message
      Dim oRecip As Recipient

      ' Create the session and log on.
      Set oSession = CreateObject("mapi.session")
      oSession.Logon

      ' Get the outbox and add the message.
      Set oOutbox = oSession.Outbox
      Set omessage = oOutbox.Messages.Add

      ' Set the properties on message.
      Set oRecip = omessage.Recipients.Add
      oRecip.Name = "conference room"
      oRecip.Resolve
      omessage.Subject = "Test message with send options set"
      omessage.Text = "This is the body."

      ' Setting the delivery time and the Expiry settings for the message.
      ' The property setting times are in a 24 hour format.
      ' Message sending options:
      ' CdoPR_DEFERRED_DELIVERY_TIME  = &HF0040
      ' CdoPR_EXPIRY_TIME             = &H150040

      ' This message will be delivered at 10:00 AM on October 23, 1998
      omessage.Fields.Item(CdoPR_DEFERRED_DELIVERY_TIME) = _
      "1998/10/23 10:00:00"

      ' This message will expire at 6:00 PM on October 23, 1998
      omessage.Fields.Item(CdoPR_EXPIRY_TIME) = "1998/10/23 18:00:00"

      ' Update the message and send it.
      omessage.Update
      omessage.Send

      ' Logoff and cleanup
      oSession.Logoff
      Set oSession = Nothing

4. Compile and run the form.

Deferred messages are spooled from the Outbox to a hidden folder on the server. Only unread items are affected by the expiration time you specify. At the time that the expiration is set, the message will be marked with a strikeout font in the Inbox. In addition, the header on the message indicates that the message expired at that time.

REFERENCES

For additional information, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q192125
   TITLE     : XFOR: Messages Set for Delayed Delivery Sent at Wrong Time

   ARTICLE-ID: Q154830
   TITLE     : XCLN: Setting Send Options for Individual Messages

   ARTICLE-ID: Q163702
   TITLE     : XCLN: Unable to Save Sent Time and Expiration Properties

Additional query words: delivery time expiration time
Keywords          : kbCDO110 kbCDO120 kbCDO121 kbMsg kbVBp kbGrpMsg 
Version           : WINDOWS:1.1,1.2,1.21
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: April 7, 1999