microsoft/mail2bug

The Autodiscover service couldn't be located.

Closed this issue · 19 comments

I am trying to setup mail2bug for the first time. We are using office 365 and TFS 2015 update 3. I have configured everything. I can open up the account that I am using for mail2bug with outlook and I can see test emails that I sent in the inbox. When I start mail2bug, it looks like everything is ok. When I send an email to the account that is being monitored, after a bit I see the following in log file:

2017-04-19 07:32:18,317 [1] INFO Mail2Bug.MainApp [(null)] - Initializing engine for instance 'Mail2BugConfigMyInstanceName' (Persistent? True)
2017-04-19 07:32:18,364 [1] INFO Mail2Bug.Mail2BugEngine [(null)] - Initalizing MailboxManager
2017-04-19 07:32:18,379 [1] INFO Mail2Bug.Helpers.DPAPIHelper [(null)] - Reading encrypted data from file .\Resources\password.bin
2017-04-19 07:32:18,379 [1] INFO Mail2Bug.Email.EWS.EWSConnectionManger [(null)] - Creating FolderMailboxManager for (tfsbuild1_svcacct@wpsic.com, CORP\tfsbuild1_svcacct, 1128924882, False)
2017-04-19 07:48:21,936 [1] INFO Mail2Bug.MainApp [(null)] - Initializing engine for instance 'Mail2BugConfigMyInstanceName' (Persistent? True)
2017-04-19 07:48:21,983 [1] INFO Mail2Bug.Mail2BugEngine [(null)] - Initalizing MailboxManager
2017-04-19 07:48:21,999 [1] INFO Mail2Bug.Helpers.DPAPIHelper [(null)] - Reading encrypted data from file .\Resources\password.bin
2017-04-19 07:48:21,999 [1] INFO Mail2Bug.Email.EWS.EWSConnectionManger [(null)] - Creating FolderMailboxManager for (tfsbuild1_svcacct@wpsic.com, CORP\tfsbuild1_svcacct, 1128924882, False)
2017-04-19 07:53:27,753 [1] ERROR Mail2Bug.MainApp [(null)] - Exception while initializing instance 'Mail2BugConfigMyInstanceName'
Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located.
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List1 redirectionEmailAddresses, Int32& currentHop) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List1 requestedSettings)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames)
at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
at Mail2Bug.Email.EWS.EWSConnectionManger.ConnectToEWS(Credentials credentials, Boolean useConversationGuidOnly) in E:\Agent_work\4\s\Mail2Bug\Email\EWS\EWSConnectionManger.cs:line 91
at Mail2Bug.Email.EWS.EWSConnectionManger.GetConnection(Credentials credentials, Boolean useConversationGuidOnly) in E:\Agent_work\4\s\Mail2Bug\Email\EWS\EWSConnectionManger.cs:line 61
at Mail2Bug.Email.MailboxManagerFactory.CreateMailboxManager(EmailSettings emailSettings) in E:\Agent_work\4\s\Mail2Bug\Email\MailboxManagerFactory.cs:line 29
at Mail2Bug.Mail2BugEngine..ctor(InstanceConfig configInstance, MailboxManagerFactory mailboxManagerFactory) in E:\Agent_work\4\s\Mail2Bug\Mail2BugEngine.cs:line 31
at Mail2Bug.MainApp.InitInstances(IEnumerable`1 configs) in E:\Agent_work\4\s\Mail2Bug\Main.cs:line 214
2017-04-19 07:53:27,769 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 0 ---------------
2017-04-19 07:53:28,783 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 1 ---------------
2017-04-19 07:53:29,797 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 2 ---------------
2017-04-19 07:53:30,811 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 3 ---------------
2017-04-19 07:53:31,825 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 4 ---------------
2017-04-19 07:53:32,839 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 5 ---------------
2017-04-19 07:53:33,853 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 6 ---------------
2017-04-19 07:53:34,867 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 7 ---------------
2017-04-19 07:53:35,881 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 8 ---------------
2017-04-19 07:53:36,895 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 9 ---------------
2017-04-19 07:53:37,908 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 10 ---------------
2017-04-19 07:53:38,922 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 11 ---------------
2017-04-19 07:53:39,936 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 12 ---------------
2017-04-19 07:53:40,950 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 13 ---------------
2017-04-19 07:53:41,964 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 14 ---------------
2017-04-19 07:53:42,978 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 15 ---------------
2017-04-19 07:53:43,992 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 16 ---------------
2017-04-19 07:53:45,006 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 17 ---------------
...

Any thoughts on what I should be looking at?

If I restart the mail2bug, It starts to initialize, and then about 3 minutes in I get an error. I'm not sure where it's failing.

E:\Mail2Bug_SVC>Mail2Bug.exe
2017-04-19 08:08:14,936 [1] INFO Mail2Bug.MainApp [(null)] - Initializing engine for instance 'Mail2BugConfigMyInstance
Name' (Persistent? True)
2017-04-19 08:08:14,982 [1] INFO Mail2Bug.Mail2BugEngine [(null)] - Initalizing MailboxManager
2017-04-19 08:08:14,998 [1] INFO Mail2Bug.Helpers.DPAPIHelper [(null)] - Reading encrypted data from file .\Resources\p
assword.bin
2017-04-19 08:08:14,998 [1] INFO Mail2Bug.Email.EWS.EWSConnectionManger [(null)] - Creating FolderMailboxManager for (t
fsbuild1_svcacct@wpsic.com, CORP\tfsbuild1_svcacct, 1128924882, False)
2017-04-19 08:11:25,908 [1] ERROR Mail2Bug.MainApp [(null)] - Exception while initializing instance 'Mail2BugConfigMyIns
tanceName'

Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located.
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String em
ailAddress, List1 redirectionEmailAddresses, Int32& currentHop) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddre ss) at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List1 requestedSettings)
at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettin
gName[] userSettingNames)
at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion reques
tedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback)
at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUr
lValidationCallback validateRedirectionUrlCallback)
at Mail2Bug.Email.EWS.EWSConnectionManger.ConnectToEWS(Credentials credentials, Boolean useConversationGuidOnly) in E
:\Agent_work\4\s\Mail2Bug\Email\EWS\EWSConnectionManger.cs:line 91
at Mail2Bug.Email.EWS.EWSConnectionManger.GetConnection(Credentials credentials, Boolean useConversationGuidOnly) in
E:\Agent_work\4\s\Mail2Bug\Email\EWS\EWSConnectionManger.cs:line 61
at Mail2Bug.Email.MailboxManagerFactory.CreateMailboxManager(EmailSettings emailSettings) in E:\Agent_work\4\s\Mail2
Bug\Email\MailboxManagerFactory.cs:line 29
at Mail2Bug.Mail2BugEngine..ctor(InstanceConfig configInstance, MailboxManagerFactory mailboxManagerFactory) in E:\Ag
ent_work\4\s\Mail2Bug\Mail2BugEngine.cs:line 31
at Mail2Bug.MainApp.InitInstances(IEnumerable`1 configs) in E:\Agent_work\4\s\Mail2Bug\Main.cs:line 214
2017-04-19 08:11:25,924 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 0 ---------------
2017-04-19 08:11:26,938 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 1 ---------------
2017-04-19 08:11:27,952 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 2 ---------------
2017-04-19 08:11:28,966 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 3 ---------------
2017-04-19 08:11:29,980 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 4 ---------------
2017-04-19 08:11:30,994 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 5 ---------------
2017-04-19 08:11:32,008 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 6 ---------------
2017-04-19 08:11:33,022 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 7 ---------------
2017-04-19 08:11:34,036 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 8 ---------------
2017-04-19 08:11:35,050 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 9 ---------------
2017-04-19 08:11:36,064 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 10 ---------------
2017-04-19 08:11:37,078 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 11 ---------------
2017-04-19 08:11:38,092 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 12 ---------------
2017-04-19 08:11:39,106 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 13 ---------------
2017-04-19 08:11:40,120 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 14 ---------------
2017-04-19 08:11:41,134 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 15 ---------------
2017-04-19 08:11:42,148 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 16 ---------------
2017-04-19 08:11:43,162 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 17 ---------------
2017-04-19 08:11:44,176 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 18 ---------------
2017-04-19 08:11:45,190 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 19 ---------------
2017-04-19 08:11:46,204 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 20 ---------------
2017-04-19 08:11:47,218 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 21 ---------------
2017-04-19 08:11:48,232 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 22 ---------------
2017-04-19 08:11:49,246 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 23 ---------------
2017-04-19 08:11:50,260 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 24 ---------------
2017-04-19 08:11:51,274 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 25 ---------------
2017-04-19 08:11:52,288 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 26 ---------------
2017-04-19 08:11:53,302 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 27 ---------------
2017-04-19 08:11:54,316 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 28 ---------------
2017-04-19 08:11:55,330 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 29 ---------------
2017-04-19 08:11:56,344 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 30 ---------------
2017-04-19 08:11:57,358 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 31 ---------------
2017-04-19 08:11:58,372 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 32 ---------------
2017-04-19 08:11:59,386 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 33 ---------------
2017-04-19 08:12:00,400 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 34 ---------------
2017-04-19 08:12:01,414 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 35 ---------------
2017-04-19 08:12:02,428 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 36 ---------------
2017-04-19 08:12:03,441 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 37 ---------------
2017-04-19 08:12:04,455 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 38 ---------------
2017-04-19 08:12:05,469 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 39 ---------------
2017-04-19 08:12:06,483 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 40 ---------------
2017-04-19 08:12:07,513 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 41 ---------------
2017-04-19 08:12:08,527 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 42 ---------------
2017-04-19 08:12:09,541 [1] INFO Mail2Bug.MainApp [(null)] - --------------- Iteration 43 ---------------
^C
E:\Mail2Bug_SVC>

Where you able to resolve this issue?

Hi All,
For me when I tested this on local environment it works fine but on development server, I am getting this error.
Any thoughts?

AuriR commented

Suggestion: Please update the component to throw an Authentication Failed or Unauthorized Access exception when a 401 is received.

Issue
It appears this error can be thrown when an authentication error occurs - like bad username + password. So, check in Fiddler and make sure you're not getting a 401, or that you're using proper credentials in your call.

So look at the values for a call like this and make sure they're valid:

        ews.Credentials = new WebCredentials(username, password);

...before calling:

        ews.AutodiscoverUrl(username, callback);

@AuriR Thanks for your suggestion, I got this issue fixed by another way. I have set URL manually instead of using AutodiscoverURL function.

@AuriR Thanks for your suggestion, I got this issue fixed by another way. I have set URL manually instead of using AutodiscoverURL function.

@vishalyadavCB - Can you give the sample code lines how it is fixed or steps to define the URL manually? as in which files you updated the URL etc..

@rajayashwanth411

replace your Autodiscover function call with following code

service.Credentials = New NetworkCredential(Email, Password)
service.Url = New Uri(ConfigurationManager.AppSettings("https://outlook.office365.com/EWS/Exchange.asmx"))

Hope this will help!!

@vishalyadavCB

Thank you for quick reply but have no luck and still struck with it. I have tried the below ways:

exchangeService.Url = new
Uri(ConfigurationManager.AppSettings("https://outlook.office365.com/EWS/Exchange.asmx"));

Got the compile time Error CS1955 Non-invocable member 'ConfigurationManager.AppSettings' cannot be used like a method.

Have changed as below (AppSettings() to AppSettings[])
exchangeService.Url = new Uri(ConfigurationManager.AppSettings["https://outlook.office365.com/EWS/Exchange.asmx"]);

When I run the code with the above got the error as UriString can not be null so added a parameter in app.config as "uriString" assigning the service URL but getting UnAuthorized 401 exception where I am able to login to the service using the same credentials to test.

Any help would be great..!

@rajayashwanth411
Sorry it was my mistake please remove ConfigurationManager.AppSettings and try

exchangeService.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");

@vishalyadavCB

Tried that option too but no luck. it says UnAuthorized 401 exception where I am able to login to the service using the same credentials to test. :(

@rajayashwanth411 I would suggest to contact your network team and see if access to above URI is permitted by your network.

The 401 Unauthorized error is an HTTP status code that means the page you were trying to access cannot be loaded until you first log in with a valid user ID and password. If you've just logged in and received the 401 Unauthorized error, it means that the credentials you entered were invalid for some reason.

Hi Vishal
I am able to login to the service manually using the same credentials without issue and can see the wsdl and methods. I am getting unauthorized when I run through the mail2bug code only. I also did testconnection using same credentials using the below test url and can login without issues.

https://testconnectivity.microsoft.com/

am I missing some thing? When we use the service url - https://outlook.office365.com/EWS/Exchange.asmx, any thing else we need to change? way of passing credentials etc...! :(

AuriR commented

Look at my comment from 29 days ago - about 9 comments up - and it has a code example for passing credentials.

@AuriR - I tried that too..but no luck. I can login using the same credentials in postman but through code it says 401 unauthorized.

@vishalyadavCB - when we change to URL from autodiscover, is there any change we need to while making call to exchange?

@rajayashwanth411: AuriR gives good advice above (~"verify your creds") before calling:
ews.AutodiscoverUrl(username, callback)

But what maybe isn't clear is that callback is a Boolean. Specifying $true avoids an error when Autodiscover is redirected to O365.

So for example the line in a script I use for creating mailbox folders via EWS looks like:
$service.AutodiscoverUrl($WindowsEmailAddress,{$true})

In your case it might be more like:
ews.AutodiscoverUrl(Joe.User@contoso.com,{$true})

Let me know if this helps.

@rajayashwanth411 -- also you can try this as your URI if you're going to hard-code a value:

https://autodiscover-s.outlook.com/EWS/Exchange.asmx

None of the above options works as the NW/Messaging team suggested to implement Managed way of authentication (Token based) instead of using the service account. Does any one implemented token based authentication for mail2Bug? any help would be appreciated.

I see. I have used that method indirectly only, within third-party EWS-reliant apps which I've deployed into Azure. I gather that what the NW team recommended to you is more or less what's demonstrated here, in the Exchange EWS docs.