I get an error when trying to connect to Exchange Web Services through ASP.NET.
The following code works if I call it through a console application, but the same code does not execute when executed on an ASP.NET web form page. As a note, I use my own credentials throughout the entire code.
"When creating a request as an account that does not have a mailbox, you must specify the primary SMTP address of the mailbox for any identifiers of the selected folder.
I thought I could fix the problem by specifying an impersonated user.
exchangeservice.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, " email@domain.com ");
But then I get another error.
"The account does not have permission to impersonate the requested user."
The application pool that the web application runs on is also my own account (just like the console application), so I donβt know what might cause this problem.
I am using the .NET framework 3.5.
Here is the complete code.
var exchangeservice = new ExchangeService(ExchangeVersion.Exchange2010_SP1) { Timeout = 10000 }; var credentials = new System.Net.NetworkCredential("username", "pass", "domain"); exchangeservice.AutodiscoverUrl(" email@domain.com ") FolderId rootFolderId = new FolderId(WellKnownFolderName.Inbox); var folderView = new FolderView(100) { Traversal = FolderTraversal.Shallow }; FindFoldersResults findFoldersResults = service.FindFolders(rootFolderId, folderView);
source share