I'm getting an error when I attempt to connect to Exchange Web Services via ASP.NET.
The following code works if I
call it via a console application but the very same code fails when executed on a ASP.NET web forms page. Just as a side note, I am using my own credentials throughout this entire code sample.
"When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids."
I thought I might be able to fix the issue by specifying an impersonated user.
exchangeservice.ImpersonatedUserId =
new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "
[email protected]");
But then I get a different error.
"The account does not have permission to impersonate the requested user."
The App Pool that the web application is running under is also my own account (same as the console application) so I have no idea what might be causing this issue.
I am using .NET framework 3.5.
Here is the code in full.
var exchangeservice =
new ExchangeService(ExchangeVersion.Exchange2010_SP1)
{
Timeout = 10000
};
var credentials = new System.Net.NetworkCredential("username", "pass", "domain");
exchangeservice.AutodiscoverUrl("
[email protected]")
FolderId rootFolderId = new FolderId(WellKnownFolderName.Inbox);
var folderView = new FolderView(100)
{
Traversal = FolderTraversal.Shallow
};
FindFoldersResults findFoldersResults =
service.FindFolders(rootFolderId, folderView);