asic properties of the mail message, attachments and any msg attachments (these need to be handled differently).
本文将集中讨论如何解剖由Outlook生成的文件。它涵盖了如何读取邮件,附件和任何msg附件的基本属性(这些都是需要不同的处理)。
Using the Code
使用代码
The code is pretty simple to use. You construct a new instance of the OutlookStorage.Message class, sending it the path to a msg file or a Stream containing an IStorage. The Stream constructor is provided so that it is easy to integrate with the Outlook drag and drop code in another of my articles and this is shown in the demo application.
代码是非常简单易用。你建设一个OutlookStorage.Message类的新实例,它发送的路径msg文件或流包含一个IStorage。在提供流构造,使其易于集成与Outlook拖放在我的文章再下降的代码,这是在演示应用程序显示。

private static void main()
{
//create new Outlook message from file
OutlookStorage.Message outlookMsg = new OutlookStorage.Message(@"C:\test.msg");
DisplayMessage(outlookMsg);
}
private static void DisplayMessage(OutlookStorage.Message outlookMsg)
{
Console.WriteLine("Subject: {0}", outlookMsg.Subject);
Console.WriteLine("Body: {0}", outlookMsg.BodyText);
Console.WriteLine("{0} Recipients", outlookMsg.Recipients.Count);
foreach (OutlookStorage.Recipient recip in outlookMsg.Recipients)
{
Console.WriteLine(" {0}:{1}", recip.Type, recip.Email);
}
Console.WriteLine("{0} Attachments", outlookMsg.Attachments.Count);
foreach (OutlookStorage.Attachment attach in outlookMsg.Attachments)
{
Console.WriteLine(" {0}, {1}b", attach.Filename, attach.Data.Length);
}
Console.WriteLine("{0} Messages", outlookMsg.Messages.Count);
foreach (OutlookStorage.Message subMessage in outlookMsg.Messages)
{
DisplayMessage(subMessage);
}
}


Save a Msg and All Attachments to the File System
保存所有的文件系统附件
This is an example on how to save a message and all associated attachments to the application path.
这是一个有关如何保存邮件和所有相关的附件的应用程序的路径例子。

private static void main()
{
//create new Outlook message from file
OutlookStorage.Message outlookMsg = new OutlookStorage.Message(@"C:\test.msg");
}
private static void SaveMessage(OutlookStorage.Message outlookMsg)
{
outlookMsg.Save(outlookMsg.Subject.Replace(":", ""));
foreach (OutlookStorage.Attachment attach in outlookMsg.Attachments)
{
byte[] attachBytes = attach.Data;
FileStream attachStream = File.Create(attach.Filename);
attachStream.Write(attachBytes, 0, attachBytes.Length);
attachStream.Close();
}
foreach (OutlookStorage.Message subMessage in outlookMsg.Messages)
{
SaveMessage(subMessage);
}
}

下载地址:
freedom831215修改

posted on 2010-07-30 10:57  freedom831215  阅读(1968)  评论(0编辑  收藏  举报