.NET如何从电子邮件中提取嵌入图像? [英] .NET How to extract embedded image from email message?

查看:146
本文介绍了.NET如何从电子邮件中提取嵌入图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在.NET 1.1中的一个项目上工作,我有一个要求,从我收到的电子邮件中提取(并保存在某处)嵌入的图像。



有人可以给我一个关于哪里开始的线索?



谢谢

解决方案

从POP服务器下载的邮件将采用文本格式,您必须解析整个邮件,并查找所有的< img /> code $ src 属性的标签设置为 cid:*



例如

 < img src ='cid:006901c6d391 $ dee64770 $ 6c822ecf @ Z2LC74Q'/> 

包含嵌入图像的电子邮件的格式如下 -

  From:foo1atbar.net 
至:foo2atbar.net
主题:一个简单的例子
Mime版本:1.0
内容类型:multipart / related;边界=边界例如; type =text / html

- 边框示例
内容类型:text / html; charset =US-ASCII

... HTML文档的文本,可能包含引用另一个正文部分中的资源的URI
,例如
例如:
< IMG SRC =cid:foo4atfoo1atbar.netALT =IETF标志>
... snip ...
内容位置:CID:somethingatelse;该标题被忽略
Content-ID:< 006901c6d391 $ dee64770 $ 6c822ecf @ Z2LC74Q>
内容类型:IMAGE / GIF
内容传输编码:BASE64

R0lGODlhGAGgAPEAAP ///// ZRaCgoAAAACH + PUNv
cHlyaWdodCAoQykgMTk5LiBVbmF1dGhvcml6ZWQgZHV
wbGljYXRpb24gcHJvaGliaXRlZC4A etc ...

... snip ...

如果你采取看看页脚,它包含一个BASE64编码版本的图像。您可以提取BASE64字符串,将其转换为基于电子邮件字符集的字节,并将其保存到文件(您可以根据Content-Type获取文件扩展名)。 Tada,完成!



希望你有一个如何做的想法!



EDIT < h2>

我也发现一个类似的问题 here 。他正在使用CDO(协作数据对象)。


Hello I'm working on a project in .NET 1.1 and I have a requirement to extract (and save it somewhere) embedded image from emails that I'm receiving.

Can someone give me a clue on where to start?

thank you

解决方案

The email downloaded from the POP server will be in text format, you will have to parse the whole email, and find all the <img /> tags having the src attribute set to cid:*

E.g.

<img src='cid:006901c6d391$dee64770$6c822ecf@Z2LC74Q' />

The format of an email containing the embedded image will be as follows -

From: foo1atbar.net 
To: foo2atbar.net 
Subject: A simple example 
Mime-Version: 1.0 
Content-Type: multipart/related; boundary="boundary-example"; type="text/html" 

--boundary-example 
Content-Type: text/html; charset="US-ASCII" 

... text of the HTML document, which might contain a URI 
referencing a resource in another body part, for example 
through a statement such as: 
<IMG SRC="cid:foo4atfoo1atbar.net" ALT="IETF logo"> 
...snip...
Content-Location: CID:somethingatelse ;this header is disregarded 
Content-ID: <006901c6d391$dee64770$6c822ecf@Z2LC74Q>
Content-Type: IMAGE/GIF 
Content-Transfer-Encoding: BASE64 

R0lGODlhGAGgAPEAAP/////ZRaCgoAAAACH+PUNv 
cHlyaWdodCAoQykgMTk5LiBVbmF1dGhvcml6ZWQgZHV 
wbGljYXRpb24gcHJvaGliaXRlZC4A etc... 

...snip...

If you take a look at the footer, it contains a BASE64 encoded version of your image. You can extract the the BASE64 string, convert it to bytes based on the email character set, and save it to a file (you can get the file extension based on the Content-Type). Tada, done!

Hope you've got an idea of how to do it!

EDIT

I also found a similary question here. He's using CDO (Collaboration Data Objects).

这篇关于.NET如何从电子邮件中提取嵌入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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