Cannot send displayed email using redemption in c#

0

I created a new email-message using Redemption-Data-Objects in C#. After calling Display(), the window is opened - all looks great.

When I try to send the message, by clicking the "send"-button, I get one of the following messages (translated from german...): "The messaging-interface returned an unknown error. try to restart outlook if the problem...." or "The element cannot be sent!"

When I use the Send-Method, all works fine, the email will be sent.

I tried OutlookSpy to find a solution - when i try to send the message i get return code 0x80020009.

Here is the sample-code:

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);

Does anybody know a solution for that problem?

regards Martin

PS: I am using office 2010 (german) an Visual Studio 2010 (english) with target framework 2.0 in my project) on Windows 7 (english).

c#
email
send
outlook-redemption
asked on Stack Overflow Mar 4, 2011 by Martin

1 Answer

0

OK...

I found the "error".

Because my session ran out of scope, the context was lost and so the error occurred.

Here is the solution:

// 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();
}
answered on Stack Overflow Mar 8, 2011 by Martin

User contributions licensed under CC BY-SA 3.0