展望嵌入式图像与内嵌图像的HTML [英] Outlook embedded image to HTML with inline image

查看:196
本文介绍了展望嵌入式图像与内嵌图像的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

展望原始电子邮件:

< 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的行动= ViewAttachment&放大器;支付= 594>

据我所知,我们可以通过获得的图像是这样的: .NET如何提取电子邮件中嵌入图像?

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

我们需要破解打开正则表达式,或是否有简化这个库?我相信,我们不是谁想要呈现的电子邮件为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.

我们从使用的 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++;
}

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

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