简体   繁体   English

从COM +自动执行Outlook

[英]Automate Outlook from COM+

I need to achieve following 我需要实现以下目标

1- Save email message as draft which user can later open, modify and send manually 1-将电子邮件另存为草稿,用户以后可以手动打开,修改和发送

2- Compose email and open outlook as new email and allow user to send or discard then and there 2-撰写电子邮件并打开Outlook作为新电子邮件,然后允许用户在那里发送或丢弃

There are sample codes using both Microsoft.Office.Interop.Outlook and SmtpClient . 有使用Microsoft.Office.Interop.OutlookSmtpClient示例代码。 I believe SmtpClient can not automate Outlook. 我相信SmtpClient无法自动执行Outlook。 And, for the second option i do not want to add reference of Microsoft.Office.Interop.Outlook because what if Office Outlook is not installed!!! 而且,对于第二个选项,我不想添加Microsoft.Office.Interop.Outlook引用,因为如果未安装Office Outlook怎么办!

So please guide me for further readings. 因此,请指导我进一步阅读。

Edit 编辑

Using no reference will surely enable the form to get open even if outlook is not installed and this can be checked by just checking null for oType after 不使用引用将确保即使未安装Outlook也可以打开表单,可以通过在之后检查oType是否为null来进行检查。

Type oType = Type.GetTypeFromProgID("Outlook.Application");

What if i add reference and client opens the form and outlook is not there OR referenced library is Office 2013 and installed library is Office 2010? 如果我添加引用并且客户端打开表单并且没有Outlook或引用的库是Office 2013而安装的库是Office 2010怎么办? would the form open or throw exception OR following lines will still work? 表单会打开还是引发异常,或者下面几行仍然有效?

Microsoft.Office.Interop.Outlook.Application myApp = new Microsoft.Office.Interop.Outlook.ApplicationClass();    
Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");

You need to clarify a bit here. 您需要在此处进行说明。 You say you want to automate Outlook, but not take a dependency on it. 您说要自动执行Outlook,但不依赖它。 That's just weird unless you're abstracting the concept of an email client, which does not seem to be your motivation. 除非您要抽象电子邮件客户端的概念,否则这很奇怪,这似乎并不是您的动机。

Assuming you do take a dependency on the interop assembly, you could check for broken/invalid references before your application actually uses that reference. 假设您确实依赖互操作程序集,则可以在应用程序实际使用该引用之前检查是否存在损坏/无效的引用。 See here. 这里

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

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