2013-09-10 36 views
0

我使用outlook redemption dll用c#語言創建outlook消息模板。與嵌入式圖像展望贖回

下面是我的代碼:

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

一切工作和圖像保存到新的位置。但是,當我檢查消息模板時,我無法在任何地方看到圖像。它代替圖像給我錯誤。

enter image description here

更新 而是嵌入圖像的,我嘗試了附上這個文件。但是當我打開文件時,我沒有看到任何附件。我用OutlookSpy檢查總附件,它給我顯示了0個附件。我的代碼是否錯誤附件?

+0

您是否使用OutlookSpy查看MSG文件(單擊OpenIMsgOnIStg)以檢查HTML是否正確,並且附件是否有正確的PR_ATTACH__CONTENTID值? –

+0

我不熟悉outlookspy,請給我更多的細節? – Hiren

+0

單擊OpenIMsgOnIStg - 您將看到IMessage窗口。檢查PR_HTML和PR_RTF_COMPRESSSED屬性。轉到GetAttachmentTabel選項卡 - 雙擊附件。 PR_ATTACH_CONTENTID屬性是否正確設置? –

回答

1

我找到了解決方案。我需要兩次電話會議。第一次保存附件到我的模板文件,並再次創建它的新實例。以下是我的代碼:

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

這對我有用。