C#解析eml文件
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
using System.Net;
using System.Net.Mail; using System.Net.Mime; using System.Threading; // 讀取郵件內(nèi)容 private void ReadEML(string emailPath) { string file = emailPath; CDO.Message oMsg = new CDO.Message(); ADODB.Stream stm = null; //讀取EML文件到CDO.MESSAGE,做分析的話,實(shí)際是用了下面的部分 try { stm = new ADODB.Stream(); stm.Open(System.Reflection.Missing.Value, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, "", ""); stm.Type = ADODB.StreamTypeEnum.adTypeBinary;//二進(jìn)制方式讀入 stm.LoadFromFile(file); //將EML讀入數(shù)據(jù)流 oMsg.DataSource.OpenObject(stm, "_stream"); //將EML數(shù)據(jù)流載入到CDO.Message,要做解析的話,后面就可以了。 //郵件的內(nèi)容 this.txtEmailContext.Text=oMsg.TextBody; MsgBody = oMsg.TextBody; //發(fā)件人 this.lblFrom.Text = oMsg.From; MsgFrom = oMsg.From; //收件人 this.lblTo.Text = oMsg.To; MsgTo = oMsg.To; //標(biāo)題 this.lblTitle.Text = oMsg.Subject; MsgSubject = oMsg.Subject; //時(shí)間 this.lblTime.Text = oMsg.ReceivedTime.ToString(); this.lblCount.Text = oMsg.Attachments.Count.ToString(); CDO.IBodyParts ip = oMsg.Attachments; int count = oMsg.Attachments.Count; for (int i = 1; i <= count; i++) { ////獲取到附件的文件名稱+后綴 object FileName = oMsg.Attachments[i].FileName; //object fileContext=oMsg.Attachments[i].GetStream(); //將附件存儲(chǔ)到指定位置 oMsg.Attachments[i].SaveToFile(@"F:\" + FileName); //ip.GetEnumerator().Current; } } catch (IOException ex) { } finally { stm.Close(); } } 該文章在 2017/10/21 18:21:45 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |