1

I use outlook Redemption dll for creating outlook message template with c# language.

Below is my code:

RedemptionLoader.DllLocation64Bit = Server.MapPath("~/bin/dlls/Redemption64.dll");
RedemptionLoader.DllLocation32Bit = Server.MapPath("~/bin/dlls/Redemption.dll");

Interop.Redemption.RDOSession session = RedemptionLoader.new_RDOSession();

var msg = session.GetMessageFromMsgFile(templatePath);

msg.Subject = String.Format("Report");

String ImageString = Server.MapPath("~\\FolderName") + "\\" + ImageName;
RDOAttachment Attach = msg.Attachments.Add(ImageString);
Attach.ContentID = "image1";
String htb = "<html><head><title>The Title</title></head><body><h1>This is some text</h1>Image 1<br /><img src=cid:image1><br /></body></html>";

msg.HTMLBody = htb;
msg.Save();
msg.SaveAs(newPath);

Everything work and image is saved to new location. But when i check that message template, i could not see Image anywhere. instead of image it gives me error.

enter image description here

Update Instead of embedded image , I tried just to attach this file. But when I open file I didn't see any attachment. I check Total Attachments with OutlookSpy, It shows me 0 attachment. Does my code wrong for attachment?

Xaruth
  • 4,034
  • 3
  • 19
  • 26
Hiren
  • 1,381
  • 5
  • 24
  • 41
  • Did you look at the MSG file with OutlookSpy (click OpenIMsgOnIStg) to check if HTML is right and the attachment is there with the right value of PR_ATTACH__CONTENTID? – Dmitry Streblechenko Sep 10 '13 at 20:23
  • I am not familiar with outlookspy, Can you please give me more details? – Hiren Sep 10 '13 at 20:26
  • Click OpenIMsgOnIStg - you will see IMessage window. Check the PR_HTML and the PR_RTF_COMPRESSSED properties. Go to the GetAttachmentTabel tab - double click the attachment. Is the PR_ATTACH_CONTENTID property correctly set? – Dmitry Streblechenko Sep 10 '13 at 22:02
  • I check this properties , On PR_RTF-COMPRESSED, I can see img tag with cid:image1 but on GetAttachmentTable, I don't see any attachment???? – Hiren Sep 10 '13 at 23:02
  • The subject of the screenshot doesn't match the subject set in your code. Could it be your actual code is (ever so slightly) different from what you posted here? Also, considering Server.MapPath, are you running this from a web application? – Paul-Jan Sep 11 '13 at 05:33
  • (which should be fine with Redemption, but it's good to know) – Paul-Jan Sep 11 '13 at 05:36
  • You are right Paul-Jan , My subject line is different in actual code. and yes I am running this from a web application – Hiren Sep 11 '13 at 16:36

1 Answers1

2

I found solution for this. I need to call session two time. First time to save attachment to my template file and than again to create new instance of it. Below is my code:

        RedemptionLoader.DllLocation64Bit = Server.MapPath("~/bin/dlls/Redemption64.dll");
        RedemptionLoader.DllLocation32Bit = Server.MapPath("~/bin/dlls/Redemption.dll");


         Interop.Redemption.RDOSession session1 = RedemptionLoader.new_RDOSession();


        var msg1 = session1.GetMessageFromMsgFile(templatePath);


        msg1.Subject = String.Format("Report");

        String ImageString = Server.MapPath("~\\FolderName") + "\\" + ImageName;
        RDOAttachment Attach = msg1.Attachments.Add(ImageString);
        Attach.ContentID = "image1";
        String htb = "<html><head><title>The Title</title></head><body><h1>This is some text</h1>Image 1<br /><img src=cid:image1><br /></body></html>";

        msg1.HTMLBody = htb;
        msg1.Save();

        Interop.Redemption.RDOSession session = RedemptionLoader.new_RDOSession();


        var msg = session.GetMessageFromMsgFile(templatePath);
        msg.SaveAs(newPath);

This works for me.

Hiren
  • 1,381
  • 5
  • 24
  • 41