【发布时间】:2023-04-05 10:08:01
【问题描述】:
我正在寻找最简单的完整示例,启动 Outlook 2007 并通过 C# .NET 启动一条新消息(我碰巧使用的是 VS2008 .NET 3.0)
这是我正在尝试的:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Outlook;
namespace CreateMessage {
class Program {
static void Main ( string[] args ) {
// Create outlook application object.
var outlookApplication = new Microsoft.Office.Interop.Outlook.Application();
// Create mail message.
var newMail = (Microsoft.Office.Interop.Outlook.MailItem)outlookApplication.CreateItem( Microsoft.Office.Interop.Outlook.OlItemType.olMailItem );
newMail.To = "example@exam.ple";
newMail.Subject = "Example";
newMail.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
newMail.HTMLBody = "<p>Dear Example,</p><p>Example example.</p>";
newMail.Display( false );
}
}
}
这是我的项目参考:
alt text http://img4.imageshack.us/img4/9350/referencesi.jpg
这是我得到的间歇性异常(大约是我运行程序的一半时间):
System.Runtime.InteropServices.COMException 未处理 Message="消息过滤器指示应用程序正忙。(来自 HRESULT 的异常:0x8001010A (RPC_E_SERVERCALL_RETRYLATER))" 来源="Interop.Microsoft.Office.Interop.Outlook" 错误代码=-2147417846 堆栈跟踪: 在 Microsoft.Office.Interop.Outlook._MailItem.set_To(字符串到) 在 C:\Users\Adam\Projects\GGS\CreateMessage\Program.cs:line 17 中的 CreateMessage.Program.Main(String[] args) 在 System.AppDomain._nExecuteAssembly(程序集程序集,字符串 [] 参数) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart() 内部异常:注意:我找到了许多关于通过 Interop 使用 Outlook 的答案和示例,但大多数答案都没有显示 using 语句,或者试图在我所追求的下一个层次上做事.我只是想让 Outlook 打开,并开始一条新消息,并且可能填写了一些信息(即主题、收件人等)。复制和粘贴到目前为止我发现的任何示例都不会编译,因为它们是 sn-ps,而不是可以编译的功能齐全的准系统示例。
谢谢!
【问题讨论】:
标签: c# .net visual-studio-2008 interop outlook