Outlook嵌入图像到HTML与内联图像 [英] Outlook embedded image to HTML with inline image

查看:658
本文介绍了Outlook嵌入图像到HTML与内联图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We have a forum solution which allows people to submit posts via email. Currently, as the mail is parsed, images are just added as attachments to the post. What we would like to do is to parse the email and take embedded images from the mail and turn them into inline images in the output HTML. We need to support any Email client Outlook, Hotmail, Gmail etc

Outlook原始电子邮件:

Outlook original Email:

< img id =Picture_x0020_1src =cid:image001.jpg@01CD172C.038D3C80>

结果是我们保存附件,并将src保存为

The desired result is that we save out the attachment and have the src as

< img id =Picture_x0020_1src =http:// www .site.com / default.aspx?action = ViewAttachment& pay = 594>

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

I am aware that we can get image through something like: .NET How to extract embedded image from email message?

我们需要破解开放RegEx吗?我相信我们不是唯一想要以HTML形式呈现电子邮件的人

Do we need to crack open the RegEx or are there libraries that simplify this? I am sure that we aren't the only people who want to render an Email as HTML

推荐答案

你当然可以下去编写代码的道路提取嵌入的图像,并自己修改身体。这可能会导致很多工作。

You certainly could go down the road of writing code to extract the embedded images, and modifying the body yourself. It would probably end up being a lot of work tho.

我们使用EasyMail.net从 http://www.quiksoft.com/

We use the EasyMail.net from http://www.quiksoft.com/

这样足够让你开始了:

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++;
}

这篇关于Outlook嵌入图像到HTML与内联图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆