无法使用c#中的兑换发送显示的电子邮件

时间:2011-03-04 17:18:21

标签: c# email send outlook-redemption

我使用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)。

1 个答案:

答案 0 :(得分: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();
}