0
votes

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!

1
Try exch.Credentials = new WebCredentials("user@domain","PASSWORD", "DOMAIN"); or exch.Credentials = new WebCredentials("user","PASSWORD", "DOMAIN");Hackerman
I tried both with the same result. The first suggestion came back with an error much faster though.DexterSlab442
I failed to mention that I can log into the newly created account using Outlook Web Access. Also, the server is running Exchange 2010.DexterSlab442
The ptennetlive article did not seem to apply. I can see the newly created account in all of the instance referenced. Thanks though!DexterSlab442

1 Answers

0
votes

Solved my own problem:

Looks like the user name I created is a bit lengthy compared to most. When I used the truncated "pre-Windows 2000" logon name of "IncomingStoreInpect" (first 19 characters), I'm able to use EWS just fine.

Haven't seen that one documented anywhere. Hope it helps someone else some day...