Outlook嵌入图像到带有内嵌图像的HTML

我们有一个论坛解决方案,允许人们通过电子邮件提交post。 目前,在解析邮件时,图像仅作为附件添加到post中。 我们想要做的是解析电子邮件并从邮件中获取嵌入的图像,并将它们转换为输出HTML中的内嵌图像。 我们需要支持任何电子邮件客户端Outlook,Hotmail,Gmail等

Outlook原创电子邮件:

期望的结果是我们保存附件并将src作为

我知道我们可以通过以下方式获取图像: .NET如何从电子邮件消息中提取嵌入的图像?

我们是否需要破解RegEx或是否有简化此操作的库? 我确信我们并不是唯一想要将电子邮件呈现为HTML的人

你当然可以编写代码来提取嵌入的图像,并自己修改身体。 它可能最终会成为很多工作。

我们使用来自http://www.quiksoft.com/的EasyMail.net

这足以让你入门:

 private POP3 pop3 = new POP3(); pop3.Connect(pop3Address, port); var memoryStream = new MemoryStream(); pop3.DownloadMessage(position, memoryStream); var email = new EmailMessage(memoryStream) var streamView = new HTMLStreamView(email, urlPrefix); string body = streamView.Body; int counter = 0; foreach (Stream stream in streamView.Streams) { if (counter != 0) { stream.Position = 0; byte[] embeddedObjectBytes = new byte[(int)stream.Length]; stream.Read(embeddedObjectBytes, 0, (int)stream.Length); string urlAndCounter = urlPrefix + counter.ToString(); string uniqueUrlAndCounter = GetUniqueUrl(urlAndCounter); if (body.Contains(urlAndCounter + "\"")) { body = body.Replace(urlAndCounter + "\"", uniqueUrlAndCounter + "\""); } else if (body.Contains(urlAndCounter + " ")) { body = body.Replace(urlAndCounter + " ", uniqueUrlAndCounter + " "); } SaveEmbeddedObject(embeddedObjectBytes,uniqueUrlAndCounter); } counter++; }