Outlook メッセージ (MSG) ファイルの読み取り

Office Automation

Microsoft Outlook 用の Office Automation オブジェクトを使用するには、プロジェクトに Microsoft Office と Microsoft Office Interop for Outlook ライブラリへの参照を追加する必要があります。

プログラミングサンプル

C#

// Add the namespaces
using Microsoft.Office;
using Microsoft.Office.Interop.Outlook;
// Create a new Application Class
Application app = new Application();
// Create a MailItem object
MailItem item = (MailItem)outlook.CreateItemFromTemplate(@"d:\temp\test.msg", Type.Missing);
// Access different fields of the message
System.Console.WriteLine(string.Format("Subject:{0}", item.Subject));
System.Console.WriteLine(string.Format("Sender Email Address:{0}", item.SenderEmailAddress));
System.Console.WriteLine(string.Format("SenderName:{0}", item.SenderName));
System.Console.WriteLine(string.Format("TO:{0}", item.To));
System.Console.WriteLine(string.Format("CC:{0}", item.CC));
System.Console.WriteLine(string.Format("BCC:{0}", item.BCC));
System.Console.WriteLine(string.Format("Html Body:{0}", item.HTMLBody));
System.Console.WriteLine(string.Format("Text Body:{0}", item.Body));

Aspose.Email for Java

以下のコードスニペットは、次と同じことを行います 上記のコード Aspose.Email for Java を使用して。

にアクセスするには Aspose.Email Outlook オブジェクトを使用するには、プロジェクトに Aspose.Email への参照を追加する必要があります。

プログラミングサンプル


// Create a new object of type MapiMessage
MapiMessage msg = MapiMessage.load("d:\\temp\\test.msg");

// Access the fields of the message
System.out.println("Subject: " + msg.getSubject());
System.out.println("Sender Email Address: " + msg.getSenderEmailAddress());
System.out.println("SenderName:{0}" + msg.getSenderName());
System.out.println("TO:{0}" + msg.getDisplayTo());
System.out.println("CC:{0}" + msg.getDisplayCc());
System.out.println("BCC:{0}" + msg.getDisplayBcc());
System.out.println("Html Body:{0}" + msg.getBodyHtml());
System.out.println("Text Body:{0}" + msg.getBody());
System.out.println("Rtf Body:{0}" + msg.getBodyRtf());