Search code examples
c#outlookoutlook-redemption

Outlook Redemption With Embedded Image


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?


Solution

  • 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.