可以通過WEBDAV的方法讀取Exchange的郵件信息,在E8.Net工作流架構的應用程序中有過這樣開發案例,因為客戶可能一開始不習慣用OUTLOOK等工具去閱讀郵件,所以通過。NET程序讀取Exchange中的郵件信息,展示在用戶的首頁上。
代碼如下:


/**//// <summary>

/// 取得未讀郵件信息

/// </summary>

/// <returns></returns>

private string GetUnReadMailList(string strUserID, string strPassWord)


...{

string url = System.Configuration.ConfigurationManager.APPSettings["ExchangeServer"];

System.Net.HttpWebRequest Request;

System.Net.WebResponse Response;

System.Net.CredentialCache MyCredentialCache;

string strRootURI = url + "/" + strUserID + "/收件箱";

string strUserName = strUserID;

//string strDomain = ConfigurationSettings.APPSettings["ExchangeDomain"];

string strDomain = System.Configuration.ConfigurationManager.APPSettings["Domain"];

string strQuery = "";

byte[] bytes = null;

System.IO.Stream RequestStream = null;

System.IO.Stream ResponseStream = null;

XmlDocument ResponseXMLDoc = null;


; Epower.DevBase.Organization.SqlDAL.UserEntity user = new Epower.DevBase.Organization.SqlDAL.UserEntity(strUserID);


string strEmailXML = "";

try


...{


strQuery = "<?xml version="1.0"?><D:searchrequest XMLns:D = "DAV:" >"

+ "<D:sql>SELECT "DAV:displayname","urn:schemas:mailheader:subject","

// + ""urn:schemas:mailheader:approved ","

// + ""urn:schemas:mailheader:comment ","

+ ""urn:schemas:mailheader:from","

+ ""urn:schemas:mailheader:date" FROM "" + strRootURI + """

+ "where "urn:schemas:httpmail:read"=false"

// + "WHERE "DAV:ishidden" = false AND "DAV:isfolder" = false"

+ "</D:sql></D:searchrequest>";


//集成驗證方式下代碼

Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);

Request.Timeout = 300000; //超時 5分鐘

MyCredentialCache = new System.Net.CredentialCache();

MyCredentialCache.Add(new System.Uri(strRootURI),

"NTLM",

new System.Net.NetworkCredential(strUserName, user.PassWord, strDomain)//

);//NTLM集成Windows驗證 Basic 基本驗證

Request.Credentials = MyCredentialCache;

//Request.Credentials = CredentialCache.DefaultNetworkCredentials;



// Specify the method.

Request.Method = "SEARCH";

// Encode the body using UTF-8.

bytes = Encoding.UTF8.GetBytes((string)strQuery);



// Set the content header length.. This must be

// done before writing data to the request stream.

Request.ContentLength = bytes.Length;



// Get a reference to the request stream.

RequestStream = Request.GetRequestStream();


// Write the SQL query to the request stream.

RequestStream.Write(bytes, 0, bytes.Length);


// Close the Stream object to release the connection

// for further use.

RequestStream.Close();


// Set the content type header.

Request.ContentType = "text/XML;charset="utf-8"";



// Send the SEARCH method request and get the

// response from the server.

Response = (HttpWebResponse)Request.GetResponse();



// Get the XML response stream.

ResponseStream = Response.GetResponseStream();


// Create the XmlDocument object from the XML response stream.

ResponseXmlDoc = new XMLDocument();

ResponseXMLDoc.Load(ResponseStream);




strEmailXml = ResponseXmlDoc.InnerXML;


ResponseStream.Close();

Response.Close();

}

catch (Exception e)
...{

// Catch any exceptions. Any error codes from the SEARCH

// method request on the server will be caught here, also.

return "";

}

return strEmailXML;

}
返回的也是XML串,經過一些處理便可以以一定的格式展示郵件的信息了
代碼的關鍵是 strQuery的XML查詢串
相關語法及信息可以參考:
http://msdn2.microsoft.com/en-us/library/ms527286.ASPx
從這裡可以找到各種字段和命名空間的意義.
通過 WebDav的方法 不但可以取得exchange郵件的信息、郵件數量,還可以與Exchange日歷進行交互。
在E8.Net工作流的一些合作伙伴中已經實現在 工作流的業務處理接口中,根據預計時間將待辦事項寫入Exchange的日歷中。 用戶通過OUTLOOK的日歷直接進入事項的相關處理。實現方法也是通過WEBDAV。 與獲取郵件的方法類似。