none
Accessing Exchange Service without user password - EWS RRS feed

  • Question

  • Hi,

       I have an Web application working in Windows integrated mode. So, there is no login page for user. We read the user identity principal. Now the application will the only the user domain account and email.

    There is a scenario to read the contacts of the logged in user. Please see my below code where i am using username and password as the credential. Please help me to access the mail server without using the domain password. 

     

     Private Shared Function GetExchangeService() As ExchangeService
            Try
                ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf RemoteCertificateValidationCallback)

                Dim exchVersion As New ExchangeVersion()


                Dim service As New ExchangeService(exchVersion)

                service.Credentials = New WebCredentials(HttpContext.Current.Session("UserName"), HttpContext.Current.Session("Password"), DomainName)

         
                service.AutodiscoverUrl(HttpContext.Current.Session("Email"))     ''Recommended.

                Return service

            Catch ex As Exception
                Return Nothing
            End Try

        End Function

     

    Wednesday, July 6, 2011 5:03 AM

Answers

  • Heeei

    I found the solution.

    after changing the code from

       service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, "anotherusername")

     

    to

       service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, "anotherusername@domainname.com")

     

    it started working.

    Wednesday, July 6, 2011 10:41 AM

All replies

  • Hi,

    it seems you are using Basic-Authentication in your scenario - this will prompt the user for his credential.

    If you want to avoid that, switch to Windows authentication. This will give you the authentication token of the user. You can use it to impersonate him during the request (Search for impersonation and ASP.NET).

    If your website runs on a different server than the Exchange server, you'll need to configure Kerberos configuration, because NTLM authentication tokens cannot be delegated (Double hop problem).

    Kind regards,
    Henning

    "Suresh Sundaresan" wrote in message news:d84dc882-0e10-4baa-92cf-63c8f3b14bcf@communitybridge.codeplex.com...

    Hi,
       I have an Web application working in Windows integrated mode. So, there is no login page for user. We read the user identity principal. Now the application will the only the user domain account and email.

    There is a scenario to read the contacts of the logged in user. Please see my below code where i am using username and password as the credential. Please help me to access the mail server without using the domain password.

    Private Shared Function GetExchangeService() As ExchangeService
           Try
               ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf RemoteCertificateValidationCallback)
                Dim exchVersion As New ExchangeVersion()
                Dim service As New ExchangeService(exchVersion)
            *    service.Credentials = New WebCredentials(HttpContext.Current.Session("UserName"), HttpContext.Current.Session("Password"), DomainName)*
                service.AutodiscoverUrl(HttpContext.Current.Session("Email")) ''Recommended.
                Return service
            Catch ex As Exception
               Return Nothing
           End Try
        End Function

    Wednesday, July 6, 2011 5:33 AM
  • HI,

       Thanks for you reply. Actually my problem is not asking the username or password. I am still in the development phase. May be my question seems to be too complicated.

    My concern is I want to make access the other persons contacts/tasks/Calendar.  I have search and found a solution to imperonate other persons account. but it gave me a error message like "The SMTP address format is invalid."

     


        Private Shared Function GetExchangeService() As ExchangeService
            Try
                ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf RemoteCertificateValidationCallback)

                Dim exchVersion As New ExchangeVersion()


                Dim service As New ExchangeService(exchVersion)

                service.Credentials = New WebCredentials(HttpContext.Current.Session("UserName"), HttpContext.Current.Session("Password"), DomainName)


                service.AutodiscoverUrl(HttpContext.Current.Session("Email"))     ''Recommended.

                service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, "anotherusername")


                Return service

            Catch ex As Exception
                Return Nothing
            End Try

     

     

    From the above code, the service is getting. But when I save the calendar, I am getting the error message.

     

    Wednesday, July 6, 2011 10:34 AM
  • Heeei

    I found the solution.

    after changing the code from

       service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, "anotherusername")

     

    to

       service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, "anotherusername@domainname.com")

     

    it started working.

    Wednesday, July 6, 2011 10:41 AM
  • Hi Suresh,

    so, your question is answered then?

    Kind regards,
    Henning Krause

    "Suresh Sundaresan" wrote in message news:5a617b18-eafb-4828-b6df-f9d77eaef374@communitybridge.codeplex.com...

    Heeei

    I found the solution.

    after changing the code from

    *   service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, "anotherusername")*

    *to*

    *   service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, "anotherusername@domainname.com")*

    it started working.

    Wednesday, July 6, 2011 2:56 PM