4
votes

I am experimenting with a small program to e-mails from an Exchange server and saving any attached files. From suggestions, I've decided to use the Redemption library.

I have installed Microsoft Exchange Server MAPI Client and Collaboration Data Objects 1.2.1 on the server so it should work without Outlook. When I run the program on my local machine, it can browse my own inbox without any problems. When I try to execute it on a server, however, I run into problems.

I get a login prompt even though I've provided the login info in the code. I am logged in at the server with a different account than the one I'm trying to access. My simplest attempt is something like:

// Get session
RDOSession session = RedemptionLoader.new_RDOSession();

// Attempt login
session.Credentials.Add("outlook.server.local", 
                        "user", 
                        "password", 
                        rdoCredentialType.ctGeneric,
                        rdoCredentialPersist.cpLocalMachine);

session.LogonExchangeMailboxEx("user",
                               "outlook.server.local",
                               false, 
                               true, 
                               "", 
                               "");

// Access mailbox
RDOFolder folder = session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox);

I get an error when I try to access the mailbox - or any other item:

Unhandled Exception: System.Runtime.InteropServices.COMException: 
  Error in IMAPI Session::OpenMsgStore: MAPI_E_LOGON_FAILED
Make sure your code runs under the Windows user identity that has MAPI profiles.

How can I access my mailbox even when logged in as a different user? If I execute the program with "Run As..." and provide my user login, it works in the server too. But I need it to work with different users.

1

1 Answers

3
votes

Ensure that your user has a Default MAPI Profile (just start Outlook and connect to any mailbox).

Then logon to the "Default Profile" using session.logon and connect to your mailbox using session.GetSharedMailbox().