简体   繁体   English

从.msg文件获取Outlook MailItem的“最佳”方法

[英]“Best” way to get an Outlook MailItem from .msg file

To pass from a .msg file to its related Outlook MailItem I found and tried these two ways: 从.msg文件传递到与其相关的Outlook MailItem,我发现并尝试了以下两种方法:

Outlook.Application oApp; // --> Outlook Application
Outlook.MailItem oItem; // --> Outlook MailItem
string file= @"C:\PWS\myMail.msg";
oApp= (Outlook.Application)new Outlook.Application();

// way #1
oItem= (Outlook.MailItem)oApp.CreateItemFromTemplate(file);
// or way #2
oItem= (Outlook.MailItem)oApp.Session.OpenSharedItem(file);

What is the difference between these two ways? 这两种方式有什么区别? I need to open the .msg and then use the resulting MailItem (to get some properties as 'SenderEmailAddress' or the email attachments)... what should I use? 我需要打开.msg,然后使用生成的MailItem(以获取一些属性作为“ SenderEmailAddress”或电子邮件附件)...我应该使用什么? At the moment they are the same to me... 此刻他们对我来说是一样的...

The third way is to use run .msg file programmatically. 第三种方法是以编程方式使用run .msg文件。 A default application (outlook) should be opened in that case. 在这种情况下,应打开默认应用程序(外观)。 For example: 例如:

 string file= @"C:\PWS\myMail.msg";
 Process.Run(file);

Be aware, you can't run multiple instance of Outlook. 请注意,您不能运行多个Outlook实例。 So, the message will be opened in the existing Outlook instance (if any). 因此,该邮件将在现有Outlook实例(如果有)中打开。

Both methods (#1 and #2) allow to open the saved message in Outlook. 两种方法(#1和#2)都允许在Outlook中打开保存的邮件。 But they have minor differences: 但是它们之间存在细微的差异:

The CreateItemFromTemplate method of the Application class creates a new Microsoft Outlook item from an Outlook template (.oft) and returns the new item. Application类的CreateItemFromTemplate方法从Outlook模板(.oft) 创建一个新的 Microsoft Outlook项目,并返回该新项目。 I'd also like to draw your attention to the fact that new items will always open in compose mode, as opposed to read mode, regardless of the mode in which the items were saved to disk. 我还想提请您注意,无论将项目保存到磁盘的方式如何,新项目始终以撰写模式(而不是读取模式)打开。

The OpenSharedItem method of the Namespace class opens a shared item from a specified path or URL. Namespace类的OpenSharedItem方法从指定的路径或URL 打开共享项 See How to: Import Saved Items using OpenSharedItem for more information. 有关更多信息,请参见如何:使用OpenSharedItem导入保存的项目

It is up to you which way to choose based on the information listed above... 您可以根据上述信息选择哪种方式...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM