.NET 如何从电子邮件中提取嵌入的图像?

发布于 2024-08-01 16:46:45 字数 100 浏览 1 评论 0原文

您好,我正在开发 .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?

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁对谁错谁最难过 2024-08-08 16:46:45

从 POP 服务器下载的电子邮件将是文本格式,您必须解析整个电子邮件,并找到所有具有 src 标签属性设置为 cid:*

例如,

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

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

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 编码版本。 您可以提取BASE64字符串,根据电子邮件字符集将其转换为字节,然后将其保存到文件中(您可以根据Content-Type获取文件扩展名)。 田田,完成!

希望您知道如何去做!

编辑

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

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文