Question

I am making an application to access a particular email account hosted on an Exchange 2003 server and do some stuff to the unread emails found. I do not really know very much about how MAPI works, so I wouldn't be too surprised if I have missed something very obvious! I am (unfortunately) using C#, I have read about the issues this may cause (and am dreading the repercussions, but my boss wants it done like this so..).

I am struggling to find any good info on how to connect to a specific account! The application will be run from someones laptop (let's say mine), so there will be a default account that Outlook connects to when opened. So:

  • Is it possible to connect to another account from a machine where the user already has there own account and probably has Outlook open?

  • If it is possible. How do I do this? When initiating the Outlook interop objects the application automatically gets the users account and sets the current user to that. I had hoped the Logon() method would sort this but no. Even just running Outlook.Application olApp = new Outlook.Application(); Goes and sets the current user to the standard account.

I hope I am making sense (probably not), but feel free to ask more detailed questions in the comments and I will reply as quickly as possible. Like I said, I know very little about MAPI and Exchange so I am struggling with how to phrase my question.

Was it helpful?

Solution

If you want to connect to a specific email account in Exchange 2003 you need to use WebDAV, CDOEX, or ExOLEDB. If you were using Exchange 2007+ you could use EWS.

Outlook Interop will only let you connect as the interactive desktop account (current logged in user). The only way to connect to other accounts is if the current interactive account has added the shared mailbox.

OTHER TIPS

If you have 2 accounts defined on one machine, you can use following: example

Outlook.Application app = new Outlook.Application();
Outlook.NameSpace ns = app.GetNamespace("MAPI");

// optional
//object missing = Type.Missing;
//ns.Logon(missing, missing, true, false);

// additional email address 
string recipientName = "myEmail@myDomain";

Outlook.Recipient recip = ns.CreateRecipient(recipientName);
recip.Resolve();

if (recip.Resolved)
{
Outlook.MAPIFolder inboxFolder = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderInbox);
}

You can also use Redemption for that - run your code as a domain user who can access the mailboxes in question, call RDOSession.LogonExchangeMailbox for that user, then open other users' mailboxes using RDOSession.GetSharedMailbox/GetSharedDefaultFolder.

Since Exchange 2013 no longer allows old style RPC connections (only RPC-over-HTTP or MAPI-over-HTTP), you can use RDOSession.LogonHostedExchangeMailbox (works for both Exchange 2013 and Exchange 2010).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top