Add / Create member(s) to a distriubutionlist

K

Kristof Ternoey

Hi

I'm trying to develop a application in VB that creates distributionlist.
That works well but I'm unable to add recipitients to the distributionlists.
They always stay empty.
I think there is no method that allows you to create a recipitient
(displayname, emailaddress) and add to that specific distributionlist.
That's my code so far:
Dim olapp As Outlook.Application
Dim mfolder As Outlook.MAPIFolder

Dim myNameSpace As Outlook.NameSpace

olapp = New Outlook.ApplicationClass

mfolder =
olapp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolde
rContacts)

Dim mydistlist As Outlook.DistListItem

Dim myRecipient As Outlook.Recipient

Dim myTempItem As Outlook.MailItem

Dim myaddressentry As Outlook.AddressEntry

Dim mycontact As Outlook.ContactItem

mydistlist = olapp.CreateItem(Outlook.OlItemType.olDistributionListItem)

myTempItem = olapp.CreateItem(Outlook.OlItemType.olMailItem)



Dim rec As Outlook.Recipient

myTempItem = olapp.CreateItem(Outlook.OlItemType.olMailItem)

mydistlist.DLName = "dfsqfdsdfsd"

myRecipient = olapp.Session.CreateRecipient("Dan Wilson")

myRecipient.Resolve()



mydistlist.AddMember(myRecipient)

mydistlist.Save()

mydistlist.Display()


Any help would be appreciated, I'm stuck

cheers
Kri
 
E

Eric Legault [MVP - Outlook]

I was able to run that code without error. However, make sure that the
recipient you are adding exists, and make sure that you click the warning
dialog (sometimes it gets hidden behind a window during debugging).
 
K

Kristof Ternoey \(

Great news erik...Problem almost solved... Thank you very much... I was
searching already 3 days...

The problem was that the contacts must be created and then saved in the
contacts.

Afterwards I could add them to my distributionlist.

Is there an option that I can hide this contacts...? I just want
distributionlist... Because the import of myCSV file contains more than 500
groups...

Cheers
 
D

Dave Kane [MVP - Outlook]

You can add one-off recipients to your DL (which are not linked to a
Contact) like this

myRecipient = olapp.Session.CreateRecipient("Member Name
<[email protected]>")
myRecipient.Resolve()
 
E

Eric Legault [MVP - Outlook]

Well, technically you can create a hidden Contact message via CDO, but that
would be overkill. Ideally it would be best to assign those Contacts to
maybe a "Hidden" category, and exclude them from displaying in any views in
the Contacts folder by creating a filter on that Category.

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top