Article ID: 174211
Article Last Modified on 5/11/2005
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
171440 Where to acquire the CDO Libraries (all versions)
Additional query words: PR_SENT_REPRESENTING
Keywords: kbhowto kbmsg KB174211