【教程】如何在C#,VB.NET中提取消息内容
2017-07-17 00:00
501 查看
摘要: 本教程介绍了如何使用Spire.Email从地址、发送地址、主题、日期和消息的正文获取消息内容。
关联工具:Spire.Email for .NET
代码片段:
Step 1:加载邮件。
Step 2:创建一个新的StringBuilder实例。
Step 3:获取我们想要的消息内容。
Step 4:写入.txt中的所有内容
提取的.text文件格式的消息内容如下:
完整代码:
[C#]
[VB.NET]
慧都控件网
关联工具:Spire.Email for .NET
代码片段:
Step 1:加载邮件。
MailMessage mail = MailMessage.Load("Sample.msg");
Step 2:创建一个新的StringBuilder实例。
StringBuilder sb = new StringBuilder();
Step 3:获取我们想要的消息内容。
//get the From address sb.AppendLine("From:"); sb.AppendLine(mail.From.Address); //get the To address sb.AppendLine("To:"); foreach (MailAddress toAddress in mail.To) { sb.AppendLine(toAddress.Address); } //get the date sb.AppendLine("Date:"); sb.AppendLine(mail.Date.ToString()); //get the subject sb.AppendLine("Subject:"); sb.AppendLine(mail.Subject); //get the BodyText sb.AppendLine("Message contents"); sb.AppendLine(mail.BodyText); //get the BodyHtml sb.AppendLine("BodyHtml"); sb.AppendLine(mail.BodyHtml);
Step 4:写入.txt中的所有内容
File.WriteAllText("ExtractMessageContents.txt", sb.ToString());
提取的.text文件格式的消息内容如下:
完整代码:
[C#]
{ MailMessage mail = MailMessage.Load("Sample.msg"); StringBuilder sb = new StringBuilder(); sb.AppendLine("From:"); sb.AppendLine(mail.From.Address); sb.AppendLine("To:"); foreach (MailAddress toAddress in mail.To) { sb.AppendLine(toAddress.Address); } sb.AppendLine("Date:"); sb.AppendLine(mail.Date.ToString()); sb.AppendLine("Subject:"); sb.AppendLine(mail.Subject); sb.AppendLine("Message contents"); sb.AppendLine(mail.BodyText); sb.AppendLine("BodyHtml"); sb.AppendLine(mail.BodyHtml); File.WriteAllText("ExtractMessageContents.txt", sb.ToString()); }
[VB.NET]
Dim mail As MailMessage = MailMessage.Load("Sample.msg") Dim sb As New StringBuilder() sb.AppendLine("From:") sb.AppendLine(mail.From.Address) sb.AppendLine("To:") For Each toAddress As MailAddress In mail.[To] sb.AppendLine(toAddress.Address) Next sb.AppendLine("Date:") sb.AppendLine(mail.[Date].ToString()) sb.AppendLine("Subject:") sb.AppendLine(mail.Subject) sb.AppendLine("Message contents") sb.AppendLine(mail.BodyText) sb.AppendLine("BodyHtml") sb.AppendLine(mail.BodyHtml) File.WriteAllText("ExtractMessageContents.txt", sb.ToString())
慧都控件网
相关文章推荐
- 【教程】如何在C#,VB.NET中提取消息内容
- Spire.Doc 教程:如何在C#,VB.NET中为Word文档插入形状和形状组
- Spire.Email 教程:如何删除C#,VB.NET中的电子邮件
- Spire.Email 教程2:如何在C#,VB.NET 中发送批量电子邮件
- 【教程】如何在C#,VB.NET中获取PDF书签
- Spire.Email 教程:如何删除C#,VB.NET中的电子邮件
- Spire.Doc 教程:如何在C#,VB.NET中为Word文档插入形状和形状组
- Word组件 Spire.Doc 教程:如何在C#,VB.NET中将XML转换为PDF
- 【教程】Excel组件Spire.XLS 教程:如何在C#,VB.NET将CSV转换为PDF
- Word组件 Spire.Doc 教程:如何在C#,VB.NET中将XML转换为PDF
- Word控件Spire.Doc 教程:用C#,VB.NET在Word中创建对书签的交叉引用
- [VB.NET]如何把.TXT的文件内容传到DATAGRID里面
- Spire.Email 教程:从C#,VB.NET中的PST文件获取文件夹信息
- Spire.Email 教程:从C#,VB.NET中的PST文件获取文件夹信息
- [VB.NET]VB2005,DataGridView如何设置当前的单元格里的内容处于编辑状态.
- Spire.Email 教程:在C#,VB.NET中搜索电子邮件
- Word教程Spire.Doc 教程:在C#,VB.NET的Word中检索所有TextRanges样式名称
- [VB.NET]VB.NET中如何实现QQ消息的效果?
- [VB.NET]请问如何取得多选中的listBox当前选中的文本内容?
- [VB.NET]怎样提取查询结果中每个子段的内容