.NET如何提取电子邮件中嵌入图像? [英] .NET How to extract embedded image from email message?
问题描述
您好我工作的一个项目,在.NET 1.1和我有一个要求,提取(并保存它的地方)的嵌入式从我收到的电子邮件的形象。
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?
谢谢
推荐答案
从POP服务器下载将文本格式的邮件,你必须分析整个电子邮件,并找到所有的&LT ; IMG />
具有的src
属性设置为 CID标签:*
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:*
例如。
<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...
如果你看一看页脚,它包含一个base64连接codeD映像的版本。您可以提取的BASE64字符串,将其转换为基于电子邮件的字符集的字节,并将其保存到一个文件中(你可以根据内容类型的文件扩展名)。田田,大功告成了!
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!
我还发现了一个类似地问题<一href="http://stackoverflow.com/questions/440356/extracting-embedded-images-from-outlook-email">here.他使用CDO(协作数据对象)。
I also found a similary question here. He's using CDO (Collaboration Data Objects).
这篇关于.NET如何提取电子邮件中嵌入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!