读取 Outlook 消息 (MSG) 文件
Contents
[
Hide
]
我们的迁移技巧展示了如何使用 Aspose 产品来改进您的应用程序,并摆脱对传统自动化的依赖。
本迁移技巧展示了如何使用两者读取 Microsoft Outlook 邮件文件并在屏幕上显示其内容 Microsoft Office 自动化 和 Aspose.Email 代码。以下示例代码仅在控制台显示内容,以帮助您了解其工作原理。请在您自己的 Windows、Web 或其他应用程序中使用这些代码片段。
Office 自动化
要在 Microsoft Outlook 中使用 Office 自动化对象,需要向项目添加对 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.fromFile("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());