0

I tried obtaining the reply to the mail by using RDOMail.Reply method. However, after inspecting the returned object, I've noticed that the signature is not part of the HTMLBody property, as it is when using method MailItem.Reply (which I'm not using because it throws 0x80004004 (E_ABORT) exception). Also, attachments that would be needed for the signature if it contains images are not preserved as they are with MailItem.Reply. I've tried applying the signature separately, using Signature object. This adds signature to the HTMLBody, but doesn't use the _MailAutoSig attribute to mark the signature part therefore if I select "Change signature" from Outlook Ribbon, signature doesn't get replaced because Outlook has no way of knowing it is a signature.

Is there a way to obtain reply from RDOMail that would contain signature Outlook knows how to replace?

    var rdoMail = session.GetMessageFromID(entryid);
    var reply = rdoMail.Reply();
    reply.HTMLBody = "";
    var Account = session.Accounts.GetOrder(rdoAccountCategory.acMail).Item(1);
    var signature = Account.ReplySignature;
    signature.ApplyTo(reply, false);
    reply.Save();
toni
  • 1
  • Redemption is supposed to copy the image attachments used used in the original HTML body. Does that not happen in your case? – Dmitry Streblechenko Apr 11 '21 at 23:35
  • Also, "_MailAutoSig" is only added in the one-off Word document Outlook uses when editing the message. RDOSignatire.Apply works with pure HTML, so "_MailAutoSig" does not apply. – Dmitry Streblechenko Apr 11 '21 at 23:37
  • - "Redemption is supposed to copy the image attachments used used in the original HTML body" original mail (the one I call Reply() on) doesn't contain attachments in the HTML body, but thats not the problem. Problem is that the RDOMail.Reply() does not apply Reply/Forward signature as the MailItem.Reply() does and doesn't contain attachments that are connected to the Reply/Forward signature whereas MailItem.Reply() does contain them. – toni Apr 12 '21 at 07:22
  • Yes, Redemption only applies a signature if RDOSignature.ApplyTo is called. But if you display the message, you might as well use MailItem.Reply. Are you trying to call it on a secondary thread? – Dmitry Streblechenko Apr 12 '21 at 14:31
  • No, its called on the main thread, basically in the code behind of the WPF control. Interestingly enough, in another flow, when I reply from Outlook Ribbon, everything works perfectly; it is MailItem.Reply (and also MailItem.ReplyAll and MailItem.Forward) that throw the exception, and I have no idea why. Also, if I simply catch the exception, it doesn't seem to have any consequences regrading mail handling.. – toni Apr 12 '21 at 19:45
  • Is that inside an Outlook addin? Or an external app? – Dmitry Streblechenko Apr 12 '21 at 20:38
  • Inside an Outlook addin – toni Apr 13 '21 at 06:42
  • Then shouldn't see an error. Is it running inside some event handler? – Dmitry Streblechenko Apr 13 '21 at 18:41
  • Yes, it is being called inside MouseLeftButtonUp event handler in the code behind of the WPF control. Do you think it could be connected to this? Basically calling the Reply method triggers the Reply event (we use AddInExpress for overriding it) and the exception happens at the moment of returning from AddInExpress code to the place where Reply method is being called. – toni Apr 13 '21 at 22:00
  • Does it work if you comment out all of your code in the Reply event handler? – Dmitry Streblechenko Apr 15 '21 at 00:50
  • Hey, it seems to be connected to the e.Cancel = true; line that we have in the code. When I comment that one out, no exception happens! – toni Apr 19 '21 at 08:49

1 Answers1

0

This is a known issue/case when dealing with Extended MAPI code and it is not related to Redemption only. See Messages that are created outside Outlook do not include the default Outlook email signature for more information.

Your choices are:

  1. Mimic the Outlook behavior by adding all the necessary parts like _MailAutoSig attribute to the message body.
  2. Use the Outlook object model with the Reply method and then getting the Redemption equivalent by using the GetRDOObjectFromOutlookObject method. But as far as I can tell, looking at the exception you get, it is not possible because the code is used from a secondary thread, right?
  3. You can use its RDOAccount object (accessible in any language, including VBA). New message signature name is stored in the 0x0016001F property, reply signature is in 0x0017001F. You can also use the RDOAccount.ReplySignature and NewSignature properties.
    Redemption also exposes RDOSignature.ApplyTo method that takes a pointer to the RDOMail object and inserts the signature at the specified location correctly merging the images and the styles:
    set Session = CreateObject("Redemption.RDOSession")
    Session.MAPIOBJECT = Application.Session.MAPIOBJECT
    set Drafts = Session.GetDefaultFolder(olFolderDrafts)
    set   Msg = Drafts.Items.Add
    Msg.To =   "user@domain.demo"
    Msg.Subject  = "testing signatures"
    Msg.HTMLBody = "<html><body>some <b>bold</b> message text</body></html>"
    set Account = Session.Accounts.GetOrder(2).Item(1)   'first mail account
    if  Not (Account  Is  Nothing)  Then
         set Signature = Account.NewMessageSignature
         if  Not (Signature  Is  Nothing)  Then
           Signature.ApplyTo Msg,  false   'apply at the bottom
         End If
    End If
    Msg.Send
Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Im not sure I can go with any of that :( 1.) I tried parsing and altering the HTMLBody, but frankly it feels like hacking, especially because it gets really messy when there are images or business cards that are part of the signature 2.)It is on the main thread. I have no clue why it throws the error, thought that it maybe has something to do with the Outlook's security issues, thats why I started Redemption in the first place 3.) Using Signature object doesn't work for me because it does not apply the _MailAutoSig attribute so selecting "Change signature" does not replace the signature – toni Apr 12 '21 at 07:31
  • I think the easiest way would be to figure out what could cause the exception and then start using the OOM which adds the signature correctly. Otherwise, you have to parse the HTML page on your own and adding the signature programmatically. – Eugene Astafiev Apr 12 '21 at 11:30
  • Thanks. I guess there's no much else left to do. – toni Apr 13 '21 at 10:00