0

我在 C# 中使用 Redemption-Data-Objects 创建了一个新的电子邮件消息。调用 Display() 后,窗口打开 - 一切看起来都很棒。

当我尝试发送消息时,通过单击“发送”按钮,我收到以下消息之一(从德语翻译...):“消息接口返回未知错误。如果出现问题,请尝试重新启动 Outlook ....”或“无法发送元素!”

当我使用发送方法时,一切正常,电子邮件将被发送。

我尝试 OutlookSpy 来寻找解决方案 - 当我尝试发送消息时,我得到返回码 0x80020009。

这是示例代码:

Redemption.RDOSession session = new Redemption.RDOSession();
session.Logon(null, null, false, null, null, null);
Redemption.RDOFolder folder = session.GetDefaultFolder(Redemption.rdoDefaultFolders.olFolderOutbox);
Redemption.RDOMail newMail = folder.Items.Add(Redemption.rdoItemType.olMailItem);

// no difference when using .Add
newMail.Recipients.AddEx("a.b@blabla.com","a.b@blabla.com", "SMTP", Redemption.rdoMailRecipientType.olTo);
newMail.Recipients.ResolveAll();
newMail.Subject = "Testmail-Subject";
newMail.HTMLBody = "Test";
newMail.Display(false, Type.Missing);

有人知道该问题的解决方案吗?

问候马丁

PS:我在 Windows 7(英语)上使用 Office 2010(德语)和 Visual Studio 2010(英语)和我的项目中的目标框架 2.0)。

4

1 回答 1

0

好的...

我发现了“错误”。

因为我的会话超出范围,上下文丢失了,所以发生了错误。

这是解决方案:

// Event object to wait for
System.Threading.ManualResetEvent _manualEvent = new ManualResetEvent(false);

private void DisplayMail() {
    ...
    // register an eventhandler for the close event
    _newMail.OnClose += new Redemption.IRDOMailEvents_OnCloseEventHandler(_newMail_OnClose);

    _newMail.Recipients.Add(txtTo);
    _newMail.Recipients.ResolveAll();
    _newMail.Subject = subject;
    _newMail.HTMLBody = body;

    _newMail.Display(false, null);
    // wait here until the message-window is closed...
    _manualEvent.WaitOne();
}

private void _newMail_OnClose()
{
    _manualEvent.Set();
}
于 2011-03-08T08:56:16.797 回答