Apoc70 / RemovePrivateFlag

Clear PRIVATE flag on Exchange mailbox messages
https://www.granikos.eu/en/justcantgetenough/PostId/303/clear-private-flag-on-mailbox-messages
MIT License
0 stars 2 forks source link

stuck at autodiscover #5

Open exentim opened 4 years ago

exentim commented 4 years ago

Hello Thomas,

what can I do to solve this?

2020-02-18 15:09:41,108 [1] ERROR RemovePrivateFlag.Program [(null)] - Connection to mailbox failed Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: Autodiscover blocked a potentially insecure redirection to https://autodiscover.yxc.de/autodiscover/autodiscover.xml. To allow Autodiscover to follow the redirection, use the AutodiscoverUrl(string, AutodiscoverRedirectionUrlValidationCallback) overload. bei Microsoft.Exchange.WebServices.Data.ExchangeService.DefaultAutodiscoverRedirectionUrlValidationCallback(String redirectionUrl) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.CallRedirectionUrlValidationCallback(String redirectionUrl) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.TryLastChanceHostRedirection[TSettings](String emailAddress, Uri redirectionUrl, TSettings& settings) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List1 redirectionEmailAddresses, Int32& currentHop) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List1 requestedSettings) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames) bei Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) bei Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) bei Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress) bei RemovePrivateFlag.Program.ConnectToExchange(String MailboxID, Boolean allowredirection, String User, String Password, Boolean Impersonisation) in D:\VSREPOSITORIES\RemovePrivateFlag\RemovePrivatFlag\Program.cs:Zeile 317.

Danke, viele Grüße

xedoc64 commented 4 years ago

Did you used the parameter “-allowredirection”?

exentim commented 4 years ago

Thanks for the quick response. No I did not. I tried it now with the following result: 2020-02-18 16:30:23,217 [1] ERROR RemovePrivateFlag.Program [(null)] - Connection to mailbox failed Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located. bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List1 redirectionEmailAddresses, Int32& currentHop) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List1 requestedSettings) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames) bei Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) bei Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) bei RemovePrivateFlag.Program.ConnectToExchange(String MailboxID, Boolean allowredirection, String User, String Password, Boolean Impersonisation) in D:\VSREPOSITORIES\RemovePrivateFlag\RemovePrivatFlag\Program.cs:Zeile 313.

exentim commented 4 years ago

In EWSEditor Autodiscover works. Maybe I have to use impersonation param. How to use the impersonation param correctly?

exentim commented 4 years ago

Thats what I try: RemovePrivateFlag.exe -mailbox tim.surname@domain.de -logonly -foldername "Posteingang" -al lowredirection -user ycx2459 -impersonate

xedoc64 commented 4 years ago

The user need to be an SMTP-address. If you use “-user” you need also pass with the option “-password” the password for the user account which should impersonate.

If you don’t pass the “-user” option the program will be use the current credentials of your session (from the command line or the powershell session).

exentim commented 4 years ago

Sorry to disturb again :) it is still not working, trying this:

RemovePrivateFlag.exe -mailbox tim.surname@domain.de -logonly -foldername "Posteingang" -allowredirection -user tim.surname@domain.de -password PasswordX -impersonate

2020-02-19 12:46:18,864 [1] INFO RemovePrivateFlag.Program [(null)] - Application started 2020-02-19 12:46:18,877 [1] DEBUG RemovePrivateFlag.Program [(null)] - Parsing arguments 2020-02-19 12:46:18,878 [1] DEBUG RemovePrivateFlag.Program [(null)] - Arguments: 2020-02-19 12:46:18,878 [1] DEBUG RemovePrivateFlag.Program [(null)] - mailbox: tim.surname@domain.de 2020-02-19 12:46:18,878 [1] DEBUG RemovePrivateFlag.Program [(null)] - Help: False 2020-02-19 12:46:18,879 [1] DEBUG RemovePrivateFlag.Program [(null)] - noconfirmation: False 2020-02-19 12:46:18,879 [1] DEBUG RemovePrivateFlag.Program [(null)] - logonly: True 2020-02-19 12:46:18,879 [1] DEBUG RemovePrivateFlag.Program [(null)] - impersonate: True 2020-02-19 12:46:18,880 [1] DEBUG RemovePrivateFlag.Program [(null)] - allowredirection: True 2020-02-19 12:46:18,880 [1] DEBUG RemovePrivateFlag.Program [(null)] - foldername: Posteingang 2020-02-19 12:46:18,880 [1] DEBUG RemovePrivateFlag.Program [(null)] - User: tim.surname@domain.de 2020-02-19 12:46:18,881 [1] DEBUG RemovePrivateFlag.Program [(null)] - Password: is set 2020-02-19 12:46:18,881 [1] DEBUG RemovePrivateFlag.Program [(null)] - ignorecertificate: False 2020-02-19 12:46:18,881 [1] DEBUG RemovePrivateFlag.Program [(null)] - server URL: using autodiscover 2020-02-19 12:46:18,883 [1] INFO RemovePrivateFlag.Program [(null)] - Connect to mailbox tim.surname@domain.de 2020-02-19 12:51:03,772 [1] ERROR RemovePrivateFlag.Program [(null)] - Connection to mailbox failed Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located. bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List1 redirectionEmailAddresses, Int32& currentHop) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List1 requestedSettings) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames) bei Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) bei Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) bei RemovePrivateFlag.Program.ConnectToExchange(String MailboxID, Boolean allowredirection, String User, String Password, Boolean Impersonisation) in D:\VSREPOSITORIES\RemovePrivateFlag\RemovePrivatFlag\Program.cs:Zeile 313. [Ended]

Any tipps? When to set param ignorecertificate and how to set param server URL? Best regards!

exentim commented 4 years ago

can this help? https://stackoverflow.com/questions/11477255/read-email-using-exchange-web-services

Maybe adding the version is needed like in EWSEditor? var service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);

The problem lies in line 313 accordng to output above. service.AutodiscoverUrl(MailboxID,RedirectionCallback); // AutodiscoverUrl(String, AutodiscoverRedirectionUrlValidationCallback)

What does your comment mean for the second part?

Please help :)

xedoc64 commented 4 years ago

I've tested the version now against O365 and an Exchange 2016. Here it works flawlessly. Against an Exchange 2019 i receive the same error message. Requesting the version with the service creation doesn't remove the error. Against which Exchange version to you running the tool?

xedoc64 commented 4 years ago

@exentim Could you please try the following build? This is working in my test lab. Requirements for .NET have changed (now 4.8). Release.zip

exentim commented 4 years ago

Hello, I tried your build. We have ExchangeVersion.Exchange2013_SP1

2020-02-20 21:38:43,533 [1] DEBUG RemovePrivateFlag.Program [(null)] - Parsing arguments 2020-02-20 21:38:43,533 [1] DEBUG RemovePrivateFlag.Program [(null)] - Arguments: 2020-02-20 21:38:43,534 [1] DEBUG RemovePrivateFlag.Program [(null)] - Mailbox: tim.surname@domain.de 2020-02-20 21:38:43,534 [1] DEBUG RemovePrivateFlag.Program [(null)] - Help: False 2020-02-20 21:38:43,535 [1] DEBUG RemovePrivateFlag.Program [(null)] - NoConfirmation: False 2020-02-20 21:38:43,535 [1] DEBUG RemovePrivateFlag.Program [(null)] - LogOnly: True 2020-02-20 21:38:43,535 [1] DEBUG RemovePrivateFlag.Program [(null)] - Impersonate: True 2020-02-20 21:38:43,536 [1] DEBUG RemovePrivateFlag.Program [(null)] - AllowRedirection: True 2020-02-20 21:38:43,536 [1] DEBUG RemovePrivateFlag.Program [(null)] - Trace fort EWS: True 2020-02-20 21:38:43,536 [1] DEBUG RemovePrivateFlag.Program [(null)] - Archive: False 2020-02-20 21:38:43,537 [1] DEBUG RemovePrivateFlag.Program [(null)] - foldername: Posteingang 2020-02-20 21:38:43,537 [1] DEBUG RemovePrivateFlag.Program [(null)] - User: tim.surname@domain.de 2020-02-20 21:38:43,537 [1] DEBUG RemovePrivateFlag.Program [(null)] - Password: is set 2020-02-20 21:38:43,538 [1] DEBUG RemovePrivateFlag.Program [(null)] - ignorecertificate: True 2020-02-20 21:38:43,538 [1] DEBUG RemovePrivateFlag.Program [(null)] - Server URL: using autodiscover 2020-02-20 21:38:43,538 [1] WARN RemovePrivateFlag.Program [(null)] - Ignoring SSL error because option -ignorecertificate is set 2020-02-20 21:38:43,540 [1] INFO RemovePrivateFlag.Program [(null)] - Connect to mailbox tim.surname@domain.de 2020-02-20 21:43:30,502 [1] ERROR RemovePrivateFlag.Program [(null)] - Connection to mailbox failed Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException: The Autodiscover service couldn't be located. bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings[TSettings](String emailAddress, List1 redirectionEmailAddresses, Int32& currentHop) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetLegacyUserSettings[TSettings](String emailAddress) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetLegacyUserSettings(String emailAddress, List1 requestedSettings) bei Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames) bei Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) bei Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) bei RemovePrivateFlag.Program.ConnectToExchange(String MailboxID, Boolean allowredirection, String User, String Password, Boolean Impersonation, Boolean Trace) [Ended]

exentim commented 4 years ago

part of trace: .................................................................... //*

tim.surname@domain.de http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a failed: WebException (Die zugrunde liegende Verbindung wurde geschlossen: Unerwarteter Fehler beim Senden..) Trying to get Autodiscover redirection URL from http://autodiscover.domain.de/autodiscover/autodiscover.xml. Redirection URL found: 'https://autodiscover.domain.de/autodiscover/autodiscover.xml' Trying to call Autodiscover for tim.surname@domain.de on https://autodiscover.domain.de/autodiscover/autodiscover.xml. POST /autodiscover/autodiscover.xml HTTP/1.1 Content-Type: text/xml; charset=utf-8 Accept: text/xml User-Agent: ExchangeServicesClient/15.00.0913.015 tim.surnname@domain.de http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a failed: WebException (Die zugrunde liegende Verbindung wurde geschlossen: Unerwarteter Fehler beim Senden..) Trying to get Autodiscover host from DNS SRV record for domain.de. DnsQuery returned error error 'Der DNS-Name ist nicht vorhanden' error code 0x0000232B. No appropriate SRV record was found. No matching Autodiscover DNS SRV records were found.
exentim commented 4 years ago

part of trace: https://0bin.net/paste/yngBLCHyTrCbjX25#iQoqbeJ1Mjj+l-csvtnbDiN2P/ZpwkLK+h+el5x22Xg

Apoc70 commented 4 years ago

Have you checked the Service Principal Name (SPN) following this post? https://techcommunity.microsoft.com/t5/exchange-team-blog/how-to-enable-kerberos-authentication-for-accessing-exchange-in/ba-p/605166 Or this post? https://medium.com/@tkolber/https-medium-com-tkolber-configure-kerberos-authentication-with-exchange-2019-72293aa234c

Can you please send a full trace (anonymized) to thomas@mcsmemail.de?