可以通过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。 与获取邮件的方法类似。
E8.Net工作流架构,企业应用开发的利器 http://***/productFlow.htm