有劳各位,求C#如何编程获取Exchange邮件问题,谢谢!
如题,我是新手,刚接触.NET就要进行编程,做上面这个东西,好多地方都还没有入门,不知如何下手,请指点一二。
------解决方案--------------------/// <summary>
/// 获得一个用户指定文件夹中的所有邮件
/// </summary>
/// <param name= "username "> 用户名 </param>
/// <param name= "domain "> 域名 </param>
/// <param name= "folder "> 文件夹 </param>
/// <param name= "password "> 密码 </param>
/// <returns> </returns>
public static ArrayList GetMessage(string username,string domain,string folder,string password)
{
ArrayList messagelist=new ArrayList();
ExchangeHelper.ExchangeHelper helper=new ExchangeHelper.ExchangeHelper();
ADODB.RecordsetClass aRS = new ADODB.RecordsetClass();
ADODB.Connection aConn ;
string strurl = String.Format( @ "file://./backofficestorage/{0}/mbx/{1}/{2}/ ",domain,username,folder);
aConn = helper.GetConnection(strurl,username,password);
if (aConn == null)
return messagelist;
//以上部分完成了打开某收件人邮箱的功能
string strQ= " ";
strQ = "select ";
strQ = strQ + " \ "urn:schemas:mailheader:thread-topic\ " "; //标题
strQ = strQ + ", \ "urn:schemas:httpmail:displayto\ " "; //收件人姓名
strQ = strQ + ", \ "urn:schemas:httpmail:displaycc\ " "; //抄送
strQ = strQ + ", \ "urn:schemas:httpmail:thread-topic\ " ";
strQ = strQ + ", \ "urn:schemas:httpmail:priority\ " " ;//级别
strQ = strQ + ", \ "urn:schemas:httpmail:importance\ " " ; //级别
strQ = strQ + ", \ "urn:schemas:mailheader:message-id\ " ";
strQ = strQ + ", \ "urn:schemas:httpmail:htmldescription\ " ";//邮件的内容
strQ = strQ + ", \ "urn:schemas:httpmail:subject\ " ";
strQ = strQ + ", \ "urn:schemas:httpmail:sendername\ " ";
strQ = strQ + ", \ "urn:schemas:mailheader:received\ " "; //收件日期
strQ = strQ + ", \ "DAV:contentclass\ " "; //项目资源的内容类别
strQ = strQ + ", \ "DAV:displayname\ " "; //项目资源在web存储系统中的名称
strQ = strQ + ", \ "DAV:id\ " "; //(相当于关系数据库中的主键)
strQ = strQ + ", \ "DAV:href\ " "; //项目资源的完整url
strQ = strQ + " from scope ( 'shallow traversal of " ;// '使用何种搜索方式
strQ = strQ + "\ " "+ strurl + "\ " ') ";
strQ = strQ + "where \ "DAV:contentclass\ "= 'urn:content-classes:message ' ";//message 是电子邮件消息或公共文件夹投寄
//以上为查询邮件主要内容的SQL语句,不要用Select *,因为这样会很慢的!
aRS.Open(strQ ,aConn,ADODB.CursorTypeEnum.adOpenForwardOnly,ADODB.LockTypeEnum.adLockReadOnly,0);
while(!aRS.EOF)
{
string id=aRS.Fields[ "DAV:id "].Value.ToString();
string strmsgurl=aRS.Fields[ "DAV:href "].Value.ToString();
string contentclass=aRS.Fields[ "DAV:contentclass "].Value.ToString();
CDO.IMessage cMsg=new CDO.MessageClass();
try
{
cMsg=helper.ReadEmail(aRS.ActiveConnection as ADODB.Connection,strmsgurl);
messagelist.Add(cMsg);
//string cc=cMsg.HTMLBody;
//cMsg.GetStream().SaveToFile(@ "d:\saf.eml ",ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
}
catch(Exception ex)
{
string bb=ex.Message;
}
aRS.MoveNext();
}
return messagelist;
}
'读取一个指定的邮件
Public Function ReadEmail(ByVal con As ADODB.Connection, ByVal url As String) As CDO.Message