pulpfiction Posted January 31, 2006 Share Posted January 31, 2006 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 More sharing options...
aspnetguy Posted January 31, 2006 Share Posted January 31, 2006 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 More sharing options...
pulpfiction Posted January 31, 2006 Author Share Posted January 31, 2006 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 More sharing options...
aspnetguy Posted January 31, 2006 Share Posted January 31, 2006 please read thishttp://www.dotnet247.com/247reference/a.as...&NoWebContent=1it clearly states that You cannot ause the Outlook Object Model under IIS, this includes ASP and ASP.Net. Link to comment Share on other sites More sharing options...
pulpfiction Posted January 31, 2006 Author Share Posted January 31, 2006 This is the output i am getting with the above code, how come????Folder Name = InboxItems in the Folder = 141And i have 141 mails in my inbox..... Link to comment Share on other sites More sharing options...
aspnetguy Posted January 31, 2006 Share Posted January 31, 2006 I am not sure I have never tried because of the above article saying it was not possible...I am stumped on this one.Can you post your full page code...I will give it a try. Link to comment Share on other sites More sharing options...
pulpfiction Posted February 1, 2006 Author Share Posted February 1, 2006 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 More sharing options...
pulpfiction Posted February 1, 2006 Author Share Posted February 1, 2006 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 More sharing options...
aspnetguy Posted February 1, 2006 Share Posted February 1, 2006 what dll did you use as a reference? what class does this code need to Inherit? Link to comment Share on other sites More sharing options...
pulpfiction Posted February 1, 2006 Author Share Posted February 1, 2006 Well I use VS 2003, reference for outlook was available in the add reference--> COM--> MS Outlook 9.0But i guess this is the dllMicrosoft.Office.Interop.Outlook.dll Link to comment Share on other sites More sharing options...
aspnetguy Posted February 1, 2006 Share Posted February 1, 2006 That is weird I only have MS Outlook 10 and 11 and I cannot find the dll...as you can tell I don't do alot of integration with other products. Link to comment Share on other sites More sharing options...
pulpfiction Posted February 1, 2006 Author Share Posted February 1, 2006 Thanks a lot for all the effort..... Link to comment Share on other sites More sharing options...
aspnetguy Posted February 1, 2006 Share Posted February 1, 2006 if you go to forums.asp.net and ask there you will get an answer for sure...there are 100,000's of members and there are a lot of MS certified people there too. Link to comment Share on other sites More sharing options...
pulpfiction Posted February 1, 2006 Author Share Posted February 1, 2006 Well tried that too, nobody cared to answer there... Link to comment Share on other sites More sharing options...
aspnetguy Posted February 1, 2006 Share Posted February 1, 2006 It does take a long time for specific questions like that...It took over a week for me ot get an answer to a graphics programming question (I had solved it by then )Well I am out of ideas...sorry again. Link to comment Share on other sites More sharing options...
pulpfiction Posted February 1, 2006 Author Share Posted February 1, 2006 Ok i guess you can help me out with this, could it be a security or access restriction when the page gets stuck in the loading stage....(with the above code) Link to comment Share on other sites More sharing options...
aspnetguy Posted February 1, 2006 Share Posted February 1, 2006 My guess would be it is a restriction of ASP.Net (I read that before) but I am not 100% sure now because you did get some results to write to the screen. Link to comment Share on other sites More sharing options...
pulpfiction Posted February 1, 2006 Author Share Posted February 1, 2006 I got a breakthrough but not sufficient, able to display Names and few other things from the contact list but when I try to display the email id's the page gets stuch in the loading page..... I am more confused now. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now