Reputation: 75
I just created a Distribution list:
$outlook = new-object -com Outlook.Application
$contacts = $outlook.Session.GetDefaultFolder(10)
$dl = $contacts.Items.Add("IPM.DistLIst")
$dl.Save()
and then created a new contact
$newcontact = $contacts.Items.Add()
$newcontact.FullName = "abc"
$newcontact.JobTitle = "abc manager"
$newcontact.Email1Address = "[email protected]"
How do I add this new contact to the newly created contact list?
I have tried:
$dl.Members.Add($newcontact)
$dl.Action.Add($newcontact)
But they both did not work,
Please help, any help will be appreciated.
Ruijie
Upvotes: 0
Views: 2488
Reputation: 49395
The AddMember method of the DistListItem class allows to add a new member to the specified distribution list. Note, the distribution list contains Recipient objects that represent valid e-mail addresses, not contacts.
Sub AddNewMember()
'Adds a member to a new distribution list
Dim objItem As Outlook.DistListItem
Dim objMail As Outlook.MailItem
Dim objRcpnt As Outlook.Recipient
Set objMail = Application.CreateItem(olMailItem)
Set objItem = Application.CreateItem(olDistributionListItem)
'Create recipient for distlist
Set objRcpnt = Application.Session.CreateRecipient("Eugene Astafiev")
objRcpnt.Resolve
objItem.AddMember objRcpnt
'Add note to list and display
objItem.DLName = "Northwest Sales Manager"
objItem.Body = "Regional Sales Manager - NorthWest"
objItem.Save
objItem.Display
End Sub
See How To: Create a new distribution list item in Outlook for more information.
Upvotes: 0