The Recipient object allows you to work with a user in Outlook. The Recipients collection contains all of the recipients in an Outlook item, such as a mail message.
Use the Add method to add a recipient to the Recipients collection. You must specify the display name of the recipient.
{Add a new recipient to the Recipients collection.} recipient = mailItem.Recipients.Add("Kim Akers");
Creating a new recipient does not ensure that the recipient has an entry in the Outlook address book. Use the Resolve method to verify that an entry exists in the address book for a recipient. |
You can retrieve a recipient from the Recipients collection with the Item method by the number associated with the recipient.
{Retrieve the third recipient from the Recipients collection.} recipient = mailItem.Recipients.Item(3);
You can also access a recipient by the display name of the recipient.
{Retrieve the recipient named "Kim Akers".} recipient = mailItem.Recipients.Item("Kim Akers");
Use the Index property to retrieve the index of the recipient in the Recipients collection.
{Retrieve the recipient’s index.} itemIndex = recipient.Index;
Use the Resolve method to resolve a recipient’s address with the addresses contained in all of the active address books. The Resolve method returns true if the recipient’s address is resolved. Otherwise, it returns false.
{Resolve the recipient’s address with the addresses in the active address books.} resolved = recipient.Resolve();
You can also use the ResolveAll method from the Recipients collection to resolve all of the recipients’ addresses simultaneously. The ResolveAll method returns true if all of the addresses are resolved. Otherwise, it returns false.
{Resolve all of the mail message’s recipients.} resolved = mailItem.Recipients.ResolveAll();
Use the Resolved property to find out if a recipient’s address has been resolved. The following example warns the user if a recipient in the Recipients collection has not been resolved.
{Warn the user if an address has not been resolved.} for i = 1 to mailItem.Recipients.Count do if(not mailItem.Recipients.Item(i).Resolved) then warning str(mailItem.Recipients.Item(i).Name) + " has not been resolved."; end if; end for;
Use the Type property and a constant from the olMailRecipientType enumeration to specify the recipient type.
{Set the recipient type to blind carbon copy.} recipient.Type = Outlook.olBCC;
Use the Name property to retrieve the display name of a recipient.
{Retrieve the recipient’s display name.} aName = str(recipient.Name);
Use the Address property to retrieve the e-mail address of a recipient.
{Retrieve a recipient’s e-mail address.} emailAddress = str(recipient.Address);
Use the Delete method from the Recipient object to delete a recipient from a mail message.
{Delete the recipient.} recipient.Delete();
You can also use the Remove method to delete a recipient from the Recipients collection. You must supply the number associated with the recipient.
{Delete the third recipient in the Recipients collection.} mailItem.Recipients.Remove(3);