Solved

C# Issue with using Outlook MAPI

Posted on 2010-08-23
2
1,709 Views
Last Modified: 2013-12-17
Hi,

Below is some pretty standard code I am using to create and login to an outlook MAPI object.

The problem is no matter what I try it always logs into my current context account (my account logged into windows) not the account I have specified at login.

The specified logins I am providing are definately correct, but the password is different here ;)

Thanks,

Xavier.
UserEmail = @"iq@epicentre.com.au";

			UserName = @"EPICENTRE\iq";

			UserPass = @"!mN0773ll!ng";



			// Create the Outlook application.

			oApp = new Microsoft.Office.Interop.Outlook.Application();

            //<--- I HAVE TRIED DOING THE LOGIN HERE

            oApp.Session.Logon(UserName, UserPass, false, false);



			// Get the NameSpace and Logon information.

			oNS = oApp.GetNamespace("mapi");



            //<--- I HAVE TRIED DOING THE LOGIN HERE AS WELL.

			//oNS.Logon(UserName, UserPass, false, false);

            

            inboxFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

            //inboxFolder.Application.NewMail += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailEventHandler(Application_NewMail);

            inboxFolder.Application.NewMailEx += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);

Open in new window

0
Comment
Question by:locdang
2 Comments
 
LVL 41

Expert Comment

by:graye
ID: 33558807
Take a look at this article that shows how to login to an outlook session:
http://msdn.microsoft.com/en-us/library/ff462097.aspx

' If not, create a new instance of Outlook and log on to the default profile.

application = New Outlook.Application()

Dim ns As Outlook.NameSpace = application.GetNamespace("MAPI")

ns.Logon("", "", Missing.Value, Missing.Value)

ns = Nothing

Open in new window

0
 
LVL 1

Accepted Solution

by:
locdang earned 0 total points
ID: 33563092
That won't work as I need to login to a specific profile, not the default one. My problem is despite me supplying credentials it still uses the default profile.

I have written a IMAP class insted and thus have bypassed  the need for the outlook objects compeletely.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now