Recipients Property (Message Object)

Recipients Property (Message Object)

The Recipients property returns a single Recipient object or a Recipients collection object. Read/write.

Syntax

Set objRecipColl = objMessage. Recipients

Set *objOneRecip = objMessage.*Recipients(index)

objRecipColl

Object. A Recipients collection object.

objMessage

Object. The Message object.

objOneRecip

Object. A single Recipient object.

index

Long. Specifies the number of the recipient within the Recipients collection. Ranges from 1 to the value specified by the Recipients collections Count property.

Data Type

Object (Recipient or Recipients collection)

Remarks

You can change individual Recipient objects within the Recipients collection, Add them to the collection, and Delete them from the collection. You can also manipulate the Recipients collection as a whole with a single Microsoft® Visual Basic® instruction. For example, you can copy the complete recipient list of a received message, with all of each recipients properties, to a reply message:

   Set objReplyMsg.Recipients = objReceivedMsg.Recipients
   Set objSenderAE = objReceivedMsg.Sender
   Set objOrigSender = objReplyMsg.Recipients.Add(objSenderAE.ID)
   ' then copy important properties from objSenderAE
 

Note that, unlike the Recipients property, the Attachments property is read-only, so the Attachments collection cannot be copied as a whole. You must deal with attachments in the manner of the following example.

The Recipients property does not correspond to a MAPI property and cannot be rendered into HTML hypertext by the CDO Rendering Library. If a Recipients collection is returned, it could be rendered as a container object by setting the ContainerRenderer object's DataSource property to the Recipients collection object returned by the Recipients property.

Example

This code fragment uses a loop to create a copy of every valid recipient of the original message objOneMsg in the copy message objCopyMsg. For each copied recipient, it also copies important properties from the original. Note how much more code this requires than copying the Recipients property from the original message.

' from the sample function Util_CopyMessage
For i = 1 To objOneMsg.Recipients.Count Step 1
    Set objOneRecip = objOneMsg.Recipients.Item(i)
    If objOneRecip Is Not Nothing Then
        Set objCopyRecip = objCopyMsg.Recipients.Add
        If objCopyRecip Is Nothing Then
            MsgBox "Unable to create recipient in message copy"
            Exit Function
        End If
        ' Now copy the most important properties
        objCopyRecip.Address = objOneRecip.Address
        objCopyRecip.Name = objOneRecip.Name
        objCopyRecip.Type = objOneRecip.Type
    End If
Next i
 

See Also

Concepts

Message Object