|
|
|
date: Fri, 7 Mar 2008 11:34:02 -0800,
group: microsoft.public.exchange.development
back
Accessing Exchange 2003 from C# app
Hi all,
I need to find out my options are for writing a C# application that connects
to an Exchange server to fetch emails. I cannot use POP3 or IMAP as they are
both disabled and the administrators are not prepared to enable them.
The application will be running on some server without Outlook installed, so
using the Outlook.Interop is not an option either, even though it is so easy
to implement :(
I have looked at the option of getting the MAPI client (
http://www.microsoft.com/downloads/details.aspx?FamilyID=E17E7F31-079A-43A9-BFF2-0A110307611E&displaylang=en
) but it appears that this is not a supported for managed code. Is this
correct? If not, are there any resources that explain how to do that?
So I think I am left with WebDAV, but I am not familiar at all with it. I
found a number of samples on the web (such as
http://blog.downtownsoftwarehouse.com/2006/10/26/using-net-and-webdav-to-access-an-exchange-server/
) which all look quite similar. Basically they do an initial request on:
http://<server>/exchweb/bin/auth/owaauth.dll
from where they get some authentication cookies, and then subsequent
requests use those cookies.
However my first request always fails with a "401 - Not Authorized". Do I
need to do an additional configuration on the Exchange server so that I can
access it using WebDAV? I haven't found anything useful so far.
Here is the code that does the initial request to get the cookies. It always
fails on request.GetRequestStream():
string authURI = server + "/exchweb/bin/auth/owaauth.dll";
// Create the web request body:
string body = string.Format( "destination={0}&username={1}&password={2}",
server + path, username, password );
byte[] bytes = Encoding.UTF8.GetBytes( body );
// Create the web request:
HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(
authURI );
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.CookieContainer = new CookieContainer();
request.ContentLength = bytes.Length;
// Create the web request content stream:
using ( Stream stream = request.GetRequestStream() ) {
stream.Write( bytes, 0, bytes.Length );
stream.Close();
}
Are there any other options apart from those I mentioned?
many thanks.
date: Fri, 7 Mar 2008 11:34:02 -0800
author: Kostas
|
|