How to access message properties that are not exposed by Active Messaging (174211)



The information in this article applies to:

  • Collaboration Data Objects (CDO) 1.1
  • Collaboration Data Objects (CDO) 1.2
  • Collaboration Data Objects (CDO) 1.21

This article was previously published under Q174211

SUMMARY

CDO (1.1, 1.2, 1.21) is a wrapper class around Extended MAPI objects. In many cases, CDO (1.1, 1.2, 1.21) exposes only a small subset of the properties actually present on the underlying Extended MAPI object.

This article provides a sample demonstrating how to access these unexposed properties.

MORE INFORMATION

Please note that while most properties can be exposed using their Property Tags, not all of them are usable by Visual Basic. Some fields require certain forms of data that Visual Basic cannot supply (such as a structure containing an array or structures).
  1. Open a new Project in Visual Basic.
  2. Add a Reference to the file CDO.DLL. (If it is not on your system in either the system or system32 subdirectory, the CDO (1.1, 1.2, 1.21) Library is not installed.)
  3. Paste the following code sample into a new Visual Basic Form containing three Command Buttons:
       Public objSession As MAPI.Session
       Public objMsg As Message
    
       Private Sub Form_Load()
        'Dim objects, then create and logon to session
        Set objSession = CreateObject("MAPI.Session")
        objSession.Logon "MyProfileNameHere"
       End Sub
    
       Private Sub Command1_Click()
        'This sample assumes you have at least one msg in your Inbox
        Set objMsg = objSession.Inbox.Messages.GetFirst()
    
        'This is where we >>look at<< unexposed properties by referencing
        'them via their Property Tag. First, we will just look at one by
        'referencing a constant defined in the CDO.DLL file. Then we look at
        'the same property by referencing the Property Tag value. Note:
        'The constants are specific to the 32-bit CDO (1.1, 1.2, 1.21) Library. 
        MsgBox "Class (using Constant): " & _
          objMsg.Fields(CdoPR_MESSAGE_CLASS)
        MsgBox "Class (using PropTag): " & _
          objMsg.Fields(&H1A001E)
        MsgBox "Flags (using Constant): " & _
          objMsg.Fields(CdoPR_MESSAGE_FLAGS)
        MsgBox "Flags (using PropTag): " & _
          objMsg.Fields(&HE070003)
       End Sub
    
       Private Sub Command2_Click()
        'NOTE: The code sample in Command2_Click demonstrates how to send
        'messages on behalf of another user.  It must be noted here, that
        'this process will fail unless the user has given you permission
        'to do this on their Exchange Server Account.
    
        'Sending on behalf of another user
        '---------------------------------
        'You can also use Property Tags to expose unexposed properties of
        'a newly created Message to add functionality supported by the
        'underlying MAPI subsystem that is not directly supported by
        'CDO (1.1, 1.2, 1.21). For example, the following code will enable
        'you to send a message on another users behalf (aka - "Sent
        'Representing"):
    
        'Dim new Message and Recip objects
        Dim objMessage As Message
        Dim objRecip As Recipient
    
        'Add a new Message to the Outbox
        Set objMessage = objSession.Outbox.Messages.Add
    
        'Get a new valid AddressEntry object
        '  >>for the person you will send on behalf of<<
        Set objRecip = objMessage.Recipients.Add
        objRecip.Name = "JoeManager"
        objRecip.Type = 1
        objRecip.Resolve
    
        'Add the needed fields to the new Message then populate with
        'values from "JoeManager's" AddressEntry object.
        '
        'As noted above under Command1_Click, you may use either the
        'PropTag or the declared constant. The "table" below shows the
        'PropTag, and the CDO (1.1, 1.2, 1.21) constant. The name each of
        'the underlying MAPI field(s) corresponds to is the same as
        'the constant name less the leading "Cdo".
        '-------------------------------------------------------------
        '&H64001E CdoPR_SENT_REPRESENTING_ADDRTYPE
        '&H65001E CdoPR_SENT_REPRESENTING_EMAIL_ADDRESS
        '&H410102 CdoPR_SENT_REPRESENTING_ENTRYID
        '&H42001E CdoPR_SENT_REPRESENTING_NAME
        '&H3B0102 CdoPR_SENT_REPRESENTING_SEARCH_KEY
    
        'As such, the following code is valid in either of
        'the two following formats:
        'objMessage.Fields.Add &H64001E, _
        '  objRecip.AddressEntry.Type
        'objMessage.Fields.Add &H65001E, _
        '  objRecip.AddressEntry.Address
        'objMessage.Fields.Add &H410102, _
        '  objRecip.AddressEntry.ID
        'objMessage.Fields.Add &H42001E, _
        '  objRecip.AddressEntry.Name
        'objMessage.Fields.Add &H3B0102, _
        '  objRecip.AddressEntry.Fields(&H300B0102).Value
        'or
        objMessage.Fields.Add _
          CdoPR_SENT_REPRESENTING_ADDRTYPE, _
          objRecip.AddressEntry.Type
        objMessage.Fields.Add _
          CdoPR_SENT_REPRESENTING_EMAIL_ADDRESS, _
          objRecip.AddressEntry.Address
        objMessage.Fields.Add _
          CdoPR_SENT_REPRESENTING_ENTRYID, _
          objRecip.AddressEntry.ID
        objMessage.Fields.Add _
          CdoPR_SENT_REPRESENTING_NAME, _
          objRecip.AddressEntry.Name
        objMessage.Fields.Add _
          CdoPR_SENT_REPRESENTING_SEARCH_KEY, _
          objRecip.AddressEntry.Fields(&H300B0102).Value
    
        'Now remove JoeManger from the Recip collection.
        'All we needed was his AddressEntry object.
        objMessage.Recipients.Delete
        Set objRecip = Nothing
    
        'Continue with remaining messaging functionality of your app.
        Set objRecip = objMessage.Recipients.Add
        objRecip.Name = "MyRecip"   'Who you are actually sending to
        objRecip.Type = 1
        objRecip.Resolve
    
        objMessage.Subject = "This is the subject"
        objMessage.Text = "This is the message body."
        objMessage.Send
       End Sub
    
       Private Sub Command3_Click()
        'Cleanup and logoff
        objSession.Logoff
        Unload Me
       End Sub
    					

REFERENCES

For information on obtaining these libraries, please see the following article in the Microsoft Knowledge Base:

171440 Where to acquire the CDO Libraries (all versions)

For additional information on how to use Property Tags to access unexposed properties, plus an extensive listing of available Property Tag constants and values see the Microsoft Developer Network Library (July 1997 or later).

Modification Type:MajorLast Reviewed:5/11/2005
Keywords:kbhowto kbMsg KB174211