Click here to Skip to main content
15,944,397 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I am building an application that has an email functionality. The email works fine except the fact that when the user sends an email using invalid credentials eg:. wrong password, the system does authenticate and instead of terminating the request,(for example if the mail receipients include internal and external) it successfully sends the email to internal receipients regardless of the wrong user credentials. But if the user is sending to receipients out side our network it authenticate successfully and terminate the request.

So I need some code that will authenticate the users credentials in OWA and confirm that the user's credentials are valid and then send the email only when the credentials are correct.

I found the code below but it always return the cookies regardless of the user credentials being invalid. Your help is highly appreciated.

VB
Private Function DoExchangeFBA() As CookieCollection
       Dim server As String = "https://mail.myechangeserver.co.za"
       Dim uri = server & "/exchweb/bin/auth/owaauth.dll"
       Dim request = DirectCast(HttpWebRequest.Create(uri), HttpWebRequest)
       request.Method = "POST"
       request.CookieContainer = New CookieContainer()
       request.ContentType = "application/x-www-form-urlencoded"
       request.AllowAutoRedirect = False
       request.ServicePoint.Expect100Continue = False
       Dim username As String = txtEmailAddress.Text
       Dim password As String = txtPassword.Text
       server = HttpUtility.UrlEncode(server)
       username = HttpUtility.UrlEncode(username)
       password = HttpUtility.UrlEncode(password)
       Dim bodyString = "destination={0}&flags=0&username={1}"
       bodyString += "&password={2}&SubmitCreds=Log+On&"
       bodyString += "forcedownlevel=0&trusted=0"
       bodyString = String.Format(bodyString, server, username, password)
       Dim body = Encoding.ASCII.GetBytes(bodyString)
       request.ContentLength = body.Length
       ServicePointManager.Expect100Continue = False
       Dim stream = request.GetRequestStream()
       stream.Write(body, 0, body.Length)
       stream.Close()
       Dim response = DirectCast(request.GetResponse(), HttpWebResponse)
      'Here is where the cookies.count always returns 2
If response.Cookies.Count < 2 Then
           Throw New AuthenticationException("Failed to login to OWA!")
       End If
       Return response.Cookies
   End Function
Posted
Updated 7-Sep-10 2:11am
v6

1 solution

Got the answer on this article. It works like a charm.
[QMailClient]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900