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"