使用 Outlook 2010 和 2013 C# 从 winform 实现发送邮件
Implement Send Mail from winform using both Outlook 2010 and 2013 C#
我已经使用 Winform 创建了一个表单来发送电子邮件。我的 Outlook 2010 Window 正在打开并且工作正常。但是,在我朋友的机器上,它不工作,因为他有 Outlook 2013。是否可以创建一个在 Outlook 2010 和 2013 上都可以工作的发送邮件。下面是我使用的代码:
var outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = this.txtTitle.Text;
mailItem.HTMLBody = this.HtmlText;
mailItem.HTMLBody = mailItem.HTMLBody + ReadSignature();
mailItem.Importance = Outlook.OlImportance.olImportanceLow;
mailItem.Display(true);
此外,我使用的 COM 是 Microsoft Outlook 14.0 Object,我知道 Outlook 2013 是 Microsoft Outlook 15.0 Object
如果你想拥有版本独立性,在添加对所需 office interop 程序集的引用后,例如 Microsoft.Office.Interop.Outlook.dll
,右键单击 dll 引用并选择属性,然后在 属性 网格中, 将 Embed Interop Types
设置为 true
.
更多信息:
Walkthrough: Embedding Type Information from Microsoft Office
Assemblies in Visual
Studio
If you embed type information in an application that references COM
objects, you can eliminate the need for a primary interop assembly
(PIA). Additionally, the embedded type information enables you to
achieve version independence for your application. That is, your
program can be written to use types from multiple versions of a COM
library without requiring a specific PIA for each version. This is a
common scenario for applications that use objects from Microsoft
Office libraries. Embedding type information enables the same build of
a program to work with different versions of Microsoft Office on
different computers without the need to redeploy either the program or
the PIA for each version of Microsoft Office.
我已经使用 Winform 创建了一个表单来发送电子邮件。我的 Outlook 2010 Window 正在打开并且工作正常。但是,在我朋友的机器上,它不工作,因为他有 Outlook 2013。是否可以创建一个在 Outlook 2010 和 2013 上都可以工作的发送邮件。下面是我使用的代码:
var outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = this.txtTitle.Text;
mailItem.HTMLBody = this.HtmlText;
mailItem.HTMLBody = mailItem.HTMLBody + ReadSignature();
mailItem.Importance = Outlook.OlImportance.olImportanceLow;
mailItem.Display(true);
此外,我使用的 COM 是 Microsoft Outlook 14.0 Object,我知道 Outlook 2013 是 Microsoft Outlook 15.0 Object
如果你想拥有版本独立性,在添加对所需 office interop 程序集的引用后,例如 Microsoft.Office.Interop.Outlook.dll
,右键单击 dll 引用并选择属性,然后在 属性 网格中, 将 Embed Interop Types
设置为 true
.
更多信息:
Walkthrough: Embedding Type Information from Microsoft Office Assemblies in Visual Studio
If you embed type information in an application that references COM objects, you can eliminate the need for a primary interop assembly (PIA). Additionally, the embedded type information enables you to achieve version independence for your application. That is, your program can be written to use types from multiple versions of a COM library without requiring a specific PIA for each version. This is a common scenario for applications that use objects from Microsoft Office libraries. Embedding type information enables the same build of a program to work with different versions of Microsoft Office on different computers without the need to redeploy either the program or the PIA for each version of Microsoft Office.