?
Solved

C# Issue with using Outlook MAPI

Posted on 2010-08-23
2
Medium Priority
?
1,902 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

743 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