


"data:image/png base64,AABBCC."ĬontentEntity entity = attachment.MimeEntity Var imageId = ("cid:", "") Īttachment attachment = attachments.FirstOrDefault(a => a.ContentId = imageId) Iterate through the "src" attributes from HTML images in reverse order.įoreach (var match in Regex.Matches(htmlBody, srcPattern, RegexOptions.IgnoreCase).Cast().Reverse()) Static string ReplaceEmbeddedImages(string htmlBody, AttachmentCollection attachments) Var rtfBody = (()) ĭ(rtfBody, rtfOptions) ĭ(message.BodyText, LoadOptions.TxtDefault) Var rtfAttachment = (a => a.FileName = "Body.rtf") Var htmlBody = ReplaceEmbeddedImages(message.BodyHtml, message.Attachments) ĭ(htmlBody, htmlOptions) Įlse if ((a => a.FileName = "Body.rtf")) Replace attached CID images to inlined DATA urls. Var htmlOptions = LoadOptions.HtmlDefault If (!string.IsNullOrEmpty(message.BodyHtml)) Static void LoadBody(MailMessage message, DocumentModel document) Import the email's body to the document. MailMessage message = MailMessage.Load("input.msg") ĭocumentModel document = new DocumentModel() Load an email (or retrieve it with POP or IMAP). Nevertheless, you can retrieve it as an Attachment named " Body.rtf".Īlso as an FYI, another problem you have is that the images from the email's HTML body are not inlined, and thus, you'll lose them when exporting to PDF.Īnyway, try using the following: static void Main() The MailMessage class currently doesn't expose API for the RTF body (only plain and HTML body). The problem occurs with specific MSG files that don't have HTML content within an RTF body, instead, they have raw RTF body.
