Exchange Server Login Credentials Setup

2.3k views Asked by At

I just want to pass this by you and make sure that I am doing this right. My code:

ExchangeService _mailService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
_mailService.Credentials = new System.Net.NetworkCredential(@"userName", @"password", @"mydomainInfo");
//_mailService.UseDefaultCredentials = true;
_mailService.Url = new Uri("https://webmail.mydomain.com/ews/exchange.asmx");

try
{
    ItemView allItems = new ItemView(100);
    SearchFilter searchFilterInbox = new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false);
    Folder _inbox = Folder.Bind(_mailService, WellKnownFolderName.Inbox);
// <SNIP>

So I get this far and the Bind returns an Authentication Fail (401). If I comment out the '.Credentials' and uncomment '.UseDefaultCredentials', I log in just fine. But I need to access a different inbox folder. I pulled the UserName and Domain Name from my account on Outlook. Even if I use my own login information, I still get this error. To me that says I'm just not providing the right information. Thoughts? I can log into the web side of the service just fine.

1

There are 1 answers

0
Young Grasshopper On BEST ANSWER

Well I solved my own problem. It was what I was suspecting. I just didn't have the correct data in the "domain" and "username" fields. I was actually calling the server the Exchange Server was on. So I changed it to the domain that my computer is logged into and changed the user id from "[email protected]" to "me" and it works! So I had it all setup right, just wrong information.