EWS Managed API - Save Draft with inline Images

守給你的承諾、 提交于 2020-01-15 06:07:46

问题


I am trying to create emails for my users using EWS Managed API 1.1, and need to use email templates our designers have created. I was able to successfully attach image (say header.png) and add an image tag like this (using cid: before the image name) in the html body.

<img width=683 height=27 src="cid:header.png" alt="Header">

This works when I use msg.SendAndSaveCopy() method. It renders perfectly fine in both Sent Mail folder and the recipients inbox. However it is not working when I try to use msg.Save() method just to save it as Draft in Drafts folder. It shows images as plain attachments and the body doesn't show images inline. They don't render properly even if I hit send in outlook. I am wondering if I need to do anything special to have these images rendered correctly in outlook Drafts folder.

Any pointers/ help will be greatly appreciated.


回答1:


Microsoft provided a workaround today to address this issue. Posting the solution for the benefit of the community

      string html = @"<html>
                 <head>
                 </head>
                 <body>
                    <img width=200 height=100  id=""1"" src=""cid:Desert.jpg"">
                 </body>
                 </html>";

        newMessage.Body = new MessageBody(BodyType.HTML, html);
        string file = @"D:\Tools\Desert.jpg";
        newMessage.Attachments.AddFileAttachment("Desert.jpg", file);
        newMessage.Attachments[0].IsInline = true;

        //this is required to fix the issue - Add content id programatically
        newMessage.Attachments[0].ContentId = "<Desert.jpg>";

        newMessage.Save();


来源:https://stackoverflow.com/questions/9518906/ews-managed-api-save-draft-with-inline-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!