C#解析eml文件
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
using System.Net;
using System.Net.Mail; using System.Net.Mime; using System.Threading; // 读取邮件内容 private void ReadEML(string emailPath) { string file = emailPath; 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;//二进制方式读入 stm.LoadFromFile(file); //将EML读入数据流 oMsg.DataSource.OpenObject(stm, "_stream"); //将EML数据流载入到CDO.Message,要做解析的话,后面就可以了。 //邮件的内容 this.txtEmailContext.Text=oMsg.TextBody; MsgBody = oMsg.TextBody; //发件人 this.lblFrom.Text = oMsg.From; MsgFrom = oMsg.From; //收件人 this.lblTo.Text = oMsg.To; MsgTo = oMsg.To; //标题 this.lblTitle.Text = oMsg.Subject; MsgSubject = oMsg.Subject; //时间 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(); //将附件存储到指定位置 oMsg.Attachments[i].SaveToFile(@"F:\" + FileName); //ip.GetEnumerator().Current; } } catch (IOException ex) { } finally { stm.Close(); } } 该文章在 2017/10/21 18:21:45 编辑过 |
关键字查询
相关文章
正在查询... |