原創|使用教程|編輯:王香|2017-07-17 14:29:04.000|閱讀 630 次
概述:本教程介紹了如何使用Spire.Email從地址、發送地址、主題、日期和消息的正文獲取消息內容。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
關聯工具: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())
熱門格式轉換工具在線訂購特惠中點擊查看>>>>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn