MSG .NET 是用于 .NET Framework / .NET Core 的 Microsoft Outlook .msg 文件 API。API 允许您轻松创建/读取/解析/转换 .msg 文件等。API 不需要在机器上安装 Microsoft Outlook 或任何其他第三方应用程序或库即可工作。
以下示例向您展示了如何打开现有文件并显示消息的某些属性。
using System;
using Independentsoft.Msg;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
Message message = new Message("c:\\temp\\message.msg");
Console.WriteLine("Subject: " + message.Subject);
Console.WriteLine("SenderName: " + message.SenderName);
Console.WriteLine("SenderEmailAddress: " + message.SenderEmailAddress);
Console.WriteLine("ReceivedByName: " + message.ReceivedByName);
Console.WriteLine("ReceivedByEmailAddress: " + message.ReceivedByEmailAddress);
Console.WriteLine("DisplayTo: " + message.DisplayTo);
Console.WriteLine("DisplayCc: " + message.DisplayCc);
Console.WriteLine("Body: " + message.Body);
Console.WriteLine("-----------------------------------------------------------------------");
Console.WriteLine("BodyHtmlText: " + message.BodyHtmlText);
Console.WriteLine("Press any key to exit.");
Console.Read();
}
}
}
以下示例向您展示了如何将 RFC822/MIME 消息(.eml 文件)转换为 Outlook 消息(.msg 文件)。
using System;
using Independentsoft.Msg;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
Independentsoft.Email.Mime.Message mimeMessage = new Independentsoft.Email.Mime.Message("c:\\test\\test.eml");
Independentsoft.Msg.Message msgMessage = new Independentsoft.Msg.Message(mimeMessage);
msgMessage.Save("c:\\test\\test.msg");
}
}
}
以下示例向您展示了如何打开一个现有文件并显示一些任务的属性。
using System;
using Independentsoft.Msg;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
Message task = new Message("c:\\temp\\task.msg");
Console.WriteLine("Subject: " + task.Subject);
Console.WriteLine("StartDate: " + task.TaskStartDate);
Console.WriteLine("EndTime: " + task.TaskDueDate);
Console.WriteLine("Owner: " + task.Owner);
Console.WriteLine("PercentComplete: " + task.PercentComplete);
Console.WriteLine("TaskStatus: " + task.TaskStatus);
Console.WriteLine("ActualWork: " + task.ActualWork);
Console.WriteLine("TotalWork: " + task.TotalWork);
Console.WriteLine("DateCompleted: " + task.DateCompleted);
Console.WriteLine("Body: " + task.Body);
Console.WriteLine("Press any key to exit.");
Console.Read();
}
}
}