Platform SDK: CDO 1.2.1

Sender Property (Message Object)

The Sender property returns or sets the sender of a message as an AddressEntry object. Read/write.

Syntax

Set objAddrEntry = objMessage.Sender

objAddrEntry
Object. The returned AddressEntry object that represents the messaging user that sent the message.
objMessage
Object. The Message object.

Data Type

Object (AddressEntry)

Remarks

You can change the Sender property before a message is either sent or saved, for example in a public folder. After a message has been sent or saved, any attempt to change its Sender property is ignored.

You can use the Sender property to send or post a message from one messaging user on behalf of another messaging user. When you set Sender to a messaging user, CDO identifies that user as both the sender of the message and the user on whose behalf the message is being sent or posted. If you then set Sender to a second messaging user, the message is identified as being sent or posted by the second messaging user on behalf of the first:

Dim objMsg As MAPI.Message ' message to be sent/posted; assume valid 
Dim objMyself As MAPI.AddressEntry ' I will send/post the message ... 
Dim objMyBoss As MAPI.AddressEntry ' ... on behalf of my boss 
' ... 
Set objMyself = objSession.CurrentUser ' AE object for myself 
Set objMyBoss = objMyself.Manager ' my boss; assume valid 
With objMsg 
  Set Sender = objMyBoss ' sets represented sender properties 
  Set Sender = objMyself ' leaves represented sender properties alone 
  .Subject = "I am sending/posting this on behalf of my manager" 
End With 
 

For more information, see "Sender Properties" and "Represented Sender Properties" in the MAPI Programmer’s Reference.

The Sender property is not exposed on AppointmentItem objects created by Microsoft® Schedule+, and it is not automatically set when you create an appointment within a CDO application. In these cases, the application must assign a value to Sender or an attempt to read it returns CdoE_NOT_FOUND.

The Sender property does not correspond to a MAPI property and cannot be rendered into HTML hypertext by the CDO Rendering Library. It could be rendered as an object by setting the ObjectRenderer object's DataSource property to the AddressEntry object returned by the Sender property.

The Name property of the AddressEntry object returned by the Sender property corresponds to the MAPI property PR_SENT_REPRESENTING_NAME. To render just the sender's name, you can set the object renderer's DataSource property to this AddressEntry object and the property parameter of the RenderProperty method to CdoPR_SENT_REPRESENTING_NAME.

Example

This code fragment displays the name of the sender of a message:

' from the sample function Message_Sender 
Set objAddrEntry = objOneMsg.Sender 
If objAddrEntry Is Nothing Then 
    MsgBox "Could not set the AddressEntry object from the Sender" 
    Exit Function 
End If 
MsgBox "Message was sent by " & objAddrEntry.Name