Jump to content

Contacts from Outlook


pulpfiction
 Share

Recommended Posts

Hi Guys,I am trying to get the mail IDs from the contacts from the MS OUTLOOK. This is the code i am using now, but not working....ERROR:System.NullReferenceException: Object reference not set to an instance of an object.

Dim oApp As Outlook.Application            Dim oname As Outlook.NameSpace = oApp.GetNamespace("MAPI")            Dim ofolder As Outlook.MAPIFolder            Dim cntfld As Outlook.MAPIFolder = oname.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)oname.Logon("username", "password", True, True)            Dim addr As Outlook.AddressList = oname.AddressLists.Item(0)            ofolder = oname.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)            Dim oMailItem As Outlook.MailItem = oApp.CreateItem(Outlook.OlItemType.olMailItem)            oMailItem.To = ofolder.Items.Item(0)            oMailItem.Subject = "This is a test mail"            oMailItem.Body = "This is a test Mail"            oMailItem.Save()            oMailItem.Send()

TIA

Link to comment
Share on other sites

here is an article that returns contact information from outlook...not sure if will work for you...it uses SharePoint...As far as I know there is no direct way to access Outlook through ASP.Net...you have to create some 'middleware' this can be a .Net desktop application that receives and stores the data in a form your webpage can read.http://blogs.msdn.com/jamescon/archive/200.../06/149709.aspx

Link to comment
Share on other sites

I want to access the Outlook in the local system, think can be done without any middleware. Found a reference MS Outlook 9.0 in COM. another change was, "impersonate=true". This code below works to a certain extent but i'am not able to get the mail ID's, any suggestions. Thanks Dim oApp As New Outlook.ApplicationDim oname As Outlook.NameSpace = oApp.GetNamespace("MAPI")Dim cCalendar As Outlook.MAPIFolder = oname.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)Dim ofolder As Outlook.MAPIFolderDim cnt As Outlook.MAPIFolder = oname.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)Response.Write("Folder Name = " + cnt.Name)Response.Write("<br>")Response.Write("Items in the Folder = ")Response.Write(cnt.Items.Count.ToString)Response.Write("<br>")Response.Write("<li>" + cnt.Items.Item(1).ToString)

Link to comment
Share on other sites

Dim oApp As Outlook.Application = New Outlook.ApplicationClass Dim oname As Outlook.NameSpace = oApp.GetNamespace("MAPI") Dim ofolder As Outlook.MAPIFolder Dim cntfld As Outlook.MAPIFolder = oname.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts) cntfld.Items.Sort("Email1Address") Response.Write(cntfld.Items.Item(1)) Dim t As Outlook.ContactItem t = cntfld.Items.Item(1) Response.Write(t.Email1Address)

Link to comment
Share on other sites

This is the full page code, i am testing this in a seperate page.Dim oApp As Outlook.Application = New Outlook.ApplicationClass Dim oname As Outlook.NameSpace = oApp.GetNamespace("MAPI") Dim ofolder As Outlook.MAPIFolder Dim cntfld As Outlook.MAPIFolder = oname.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts) cntfld.Items.Sort("Email1Address") Response.Write(cntfld.Items.Item(1)) Dim t As Outlook.ContactItem t = cntfld.Items.Item(1) Response.Write(t.Email1Address)What i noticed is that when i comment the code in the red, i get the o/p somthing like this. for the line in GREENSystem.__ComObjectBut when I uncomment the RED part it is not displaying the page. Loading take a very long time, what could be wrong.......

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...