【问题标题】:.NET How to extract embedded image from email message?.NET 如何从电子邮件中提取嵌入的图像?
【发布时间】:2010-11-18 13:27:59
【问题描述】:

您好,我正在使用 .NET 1.1 开发一个项目,我需要从收到的电子邮件中提取(并将其保存在某处)嵌入图像。

谁能告诉我从哪里开始?

谢谢

【问题讨论】:

  • 来自前景?网络邮件?还是别的什么?
  • 您是如何收到邮件的?使用展望?通过使用 POP3 或 IMAP 组件?还有什么?
  • 嗯,是的,我们正在使用 POP3,第三方组件用于从电子邮件服务器检索电子邮件。它是 OpenPOP.net 组件...
  • 几乎类似的 SO 问题:stackoverflow.com/questions/440356/…

标签: .net image email extract embedded-resource


【解决方案1】:

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

例如

<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 获取文件扩展名)。多田,完成!

希望你已经知道怎么做!

编辑

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

【讨论】:

    猜你喜欢
    • 2010-10-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    • 2011-04-16
    • 2010-12-23
    • 1970-01-01
    • 2011-10-30
    相关资源
    最近更新 更多