4
votes

This Microsoft page indicates that by setting the UseDefaultCredentials property to true, no login name and password are required to communicate with the Exchange server. However, that is not my experience.

My code creates an instance of ExchangeService called service:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);

If I manually set the credentials as follows, everything works just fine:

service.Credentials = new WebCredentials("[email protected]", "my password");

However, if I remove that line and replace it with the following, my code doesn't work:

service.UseDefaultCredentials = true;

I have searched and searched for solutions but I'm not finding anything concrete. If someone here could please help me I would be very grateful.

EDIT: I tried to use my own credentials instead of the Default Credentials.

string smtpaddress = "[email protected]";
es.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
es.Credentials = new WebCredentials("myemail", "mypassword");
es.AutodiscoverUrl(smtpaddress, RedirectionCallback);
FolderId SharedMailbox = new FolderId(WellKnownFolderName.Inbox, "[email protected]");
Folder sharedInbox = Folder.Bind(es, SharedMailbox);

At this point I can check sharedInbox containing the details of the Inbox. I can see the unread email count and others.

But when I access

ItemView itemView = new ItemView(100);
FindItemsResults<Item> findResults1 = es.FindItems(pqInbox.Id, itemView);

I get exception "SMTP address has no mailbox associated with it"

2
do you find any solution?love thakker

2 Answers

3
votes

my experience in that case is, that if you set service.UseDefaultCredentials = true your Login of your pc will be taken. Which works perfect if your in the same ActiveDirectory structure as the exchangeserver is. If your trying to connect to the exchange server from outside of the ADS you will have to set the credentials manually.

I'm using the defaultcredentials for my tools when I'm at work. If I connect from at home I have to set the credentials.

Hope that helps you...

2
votes

From MSDN documentation, UseDefaultCredentials is ignored in Exchange Online. You must specify credentials for Exchange Online.

http://msdn.microsoft.com/en-us/library/office/microsoft.exchange.webservices.data.exchangeservicebase.usedefaultcredentials(v=exchg.80).aspx