I'm new to coding EWS in VB.Net. My goal is to extract attachments from messages arriving in a designated inbox and save them to a specified folder. I tested some code that seemed to work great when used against my domain/Exchange account.
I then created a new account and attempted to use the same code. It started producing an error:
The request failed. The remote server returned an error: (401) Unauthorized.
The code is pretty basic so far:
Dim exch As ExchangeService = New ExchangeService(ExchangeVersion.Exchange2010_SP2)
exch.Url = New Uri("https://mail.OURSERVER.com/EWS/Exchange.asmx")
exch.UseDefaultCredentials = False
exch.Credentials = New System.Net.NetworkCredential("IncomingStoreInspections", "PASSWORD", "DOMAIN")
Dim iv As ItemView = New ItemView(100)
iv.Traversal = ItemTraversal.Shallow
Dim InboxItems As FindItemsResults(Of Item) = Nothing
InboxItems = exch.FindItems(WellKnownFolderName.Inbox, iv)
The error is produced by the last line.
So far I've compared the domain account and mailbox properties of the working user and the newly created user and haven't come up with anything useful. Thanks in advance!
exch.Credentials = new WebCredentials("user@domain","PASSWORD", "DOMAIN");
orexch.Credentials = new WebCredentials("user","PASSWORD", "DOMAIN");
– Hackerman