///
/// 取得eml文件的内容
///
public Hashtable ReadEML(string file)
{
Hashtable mailinfo = new Hashtable();
CDO.Message oMsg = new CDO.Message();
ADODB.Stream stm = null;
//讀取EML文件到CDO.MESSAGE做分析
try
{
stm = new ADODB.Stream();
stm.Open(System.Reflection.Missing.Value,
ADODB.ConnectModeEnum.adModeUnknown,
ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified,
"", "");
stm.Type = ADODB.StreamTypeEnum.adTypeBinary;//二進位方式讀入
if (System.IO.File.Exists(file))
{
stm.LoadFromFile(file); //將EML讀入資料流程
oMsg.DataSource.OpenObject(stm, "_stream"); //將EML資料流程載入到CDO.Message做解析
mailinfo.Add("body", oMsg.HTMLBody); //本文
mailinfo.Add("Sender", oMsg.From); //發信者
mailinfo.Add("Subject", oMsg.Subject); //主旨
mailinfo.Add("mailto", oMsg.To); //收件者
}
//處理附件
int count = oMsg.Attachments.Count;
if (count != 0)
{
for (int i = 1; i <= count; i++)
{
//將附件存檔
object FileName = oMsg.Attachments[i].FileName;
oMsg.Attachments[i].SaveToFile(HttpContext.Current.Server.MapPath("/" + FileName));
}
}
}
catch (IOException ex)
{
}
finally
{
stm.Close();
}
return mailinfo;//回傳MAIL資訊
}
#endregion
本方法須先取得CDO.dll
https://skydrive.live.com/redir?resid=AEBD49EB991DDEC8!2557
其他回傳值參考圖
