For days now I've been trying to create a Distribution List in Outlook from my VB.net app. I can create one but I cannot put any members in it because there seems to be no way to define and create a recipient. This used to work in older versions of VB but now Microsoft seems to have changed something.
Here is my code:
Here is my code:
Code:
' Start Outlook.
' If it is already running, you'll use the same instance...
Dim olApp As Microsoft.Office.Interop.Outlook.Application
olApp = CreateObject("Outlook.Application")
' Logon. Doesn't hurt if you are already running and logged on...
Dim olNs As Microsoft.Office.Interop.Outlook.NameSpace
olNs = olApp.GetNamespace("MAPI")
olNs.Logon()
' Create and Open a new contact.
Dim olItem As Microsoft.Office.Interop.Outlook.ContactItem
olItem = olApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olContactItem)
' Create a new Distribution List
Dim myDistList As Microsoft.Office.Interop.Outlook.DistListItem
myDistList = olApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olDistributionListItem)
' Create a new MailItem
Dim myMailItem As Microsoft.Office.Interop.Outlook.MailItem
myMailItem = olApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
Dim myRecip As Microsoft.Office.Interop.Outlook.Recipient
myRecip = olApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.recipient)
[B]' this line above fails saying recipient is not a member of microsoft.office.interop.outlook.olitemtype[/B]
myDistList.DLName = "Test List"
myDistList.AddMember(myRecip)
myDistList.Save()
olApp = Nothing
olNs.Logoff()
olNs = Nothing
olItem = Nothing
myDistList = Nothing
myMailItem = Nothing