none
Exchange 2013: getting Access is denied. Check credentials and try again RRS feed

  • Question

  • Hello,

    I have given Permission to Exchange mailbox database using cmdlet

    Get-MailboxDatabase | Add-ADPermission -user administrator -AccessRights GenericAll -ExtendedRights Receive-As, Send-As

    and then I ran  the following code and got the error "Access is denied. Check credentials and try again."  

    ===================== Code ======================           

    namespace TestAppEWS {
        class Program {
            static void Main(string[] args) {
                try {

                    ExchangeServiceBinding ebExchangeServiceBinding = createesb("administrator", "pass@123", "domain.Lab", string.Empty);
                    UserOofSettings uoUserOofSettings = ewsGetOOF(ebExchangeServiceBinding, "user2@org.local1");
                }
                catch (Exception ex) {
                    Console.WriteLine("Unhandle exception is occured. Message:"+ex.Message);
                }

                Console.ReadKey();
            }

            static void GetExchangeVersion() {
                ExchangeServiceBinding obj = new ExchangeServiceBinding();
            }
           static ExchangeServiceBinding createesb(string UserName, string Password, string Domain, string OofURL) {
                ServicePointManager.ServerCertificateValidationCallback =
                 delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) {
                     //   Ignore Self Signed Certs
                     return true;
                 };
                ExchangeServiceBinding ebExchangeServiceBinding = new ExchangeServiceBinding();
                ebExchangeServiceBinding.RequestServerVersionValue = new RequestServerVersion();
                ebExchangeServiceBinding.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2013;
                if (UserName == "") {
                    ebExchangeServiceBinding.UseDefaultCredentials = true;
                }
                else {
                    ebExchangeServiceBinding.Credentials = new NetworkCredential(UserName, Password, Domain);
                    Console.WriteLine("NetworkCredential ncNetCredential==> "+UserName);
                }
                if (OofURL == "") {
                    OofURL = "https://Exch2013.domain.Lab/EWS/Exchange.asmx";
                }
                ebExchangeServiceBinding.Url = OofURL;
                Console.WriteLine("Oof url: " + ebExchangeServiceBinding.Url);

               return ebExchangeServiceBinding;

            }

           static UserOofSettings ewsGetOOF(ExchangeServiceBinding ebExchangeServiceBinding, String emEmailAddress) {
               Console.WriteLine("email Address==> " + emEmailAddress);
               GetUserOofSettingsRequest goGetUserOofSettings = new GetUserOofSettingsRequest();
               UserOofSettings ouOffSetting = null;
               EmailAddress mbMailbox = new EmailAddress();
               mbMailbox.Address = emEmailAddress;
               goGetUserOofSettings.Mailbox = mbMailbox;
              // ebExchangeServiceBinding.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap12;
               Console.WriteLine("goGetUserOofSettings mailbox.Address ==>" + goGetUserOofSettings.Mailbox.Address);
               GetUserOofSettingsResponse goGetOoFResponse = ebExchangeServiceBinding.GetUserOofSettings(goGetUserOofSettings);
               Console.WriteLine("goGetOoFResponse.ResponseMessage.MessageText ==>" + goGetOoFResponse.ResponseMessage.MessageText);
               Console.WriteLine("goGetOoFResponse.ResponseMessage.ResponseClass ==>" + goGetOoFResponse.ResponseMessage.ResponseClass);
               if (goGetOoFResponse.ResponseMessage.ResponseClass == ResponseClassType.Success) {
                   ouOffSetting = goGetOoFResponse.OofSettings;
               }
               else {
                   throw new Exception(goGetOoFResponse.ResponseMessage.MessageText.ToString());
               }

               return ouOffSetting;
           }
        }
    }

    ===================== end Code ======================

    can you please tell me what exact issue in Exchange 2013 CU1? Same code is successfully ran on Exchange 2010 SP2.

    thanks in Advance

    Br,

    Anil Avhad


    Tuesday, August 6, 2013 10:49 AM

All replies

  • Out of curiousity, does this work with a non-Exchange or Domain admin account credentials?  If you attempt to access UserX's mailbox and use UserX's credentials, does it work?  If so, then it might not be the code.
    Thursday, August 8, 2013 1:48 PM