将保存在磁盘上的 eml 文件加载到 .net Mail.Message 对象中
我的硬盘上保存有 .eml 文件,我想编写一个 .net 方法,该方法类似于 Sub LoadMessage(byval path as String)。我该怎么做呢?
我正在使用 .Net 2.0 - C# 或 VB.Net 都可以工作。我会用给定的文件打开文件流对象吗?我只是不知道如何将其从流中获取到 Mail.Message 对象中。
I have .eml files saved on my hard drive and i'd like to write a .net method that would be along the lines of Sub LoadMessage(byval path as String)
. How would I go about doing this?
I'm using .Net 2.0 - and C# or VB.Net either will work. Would I open a filestream object with the given file? I just don't know how to get it from the stream into the Mail.Message object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
System.Net.Mail 中没有方法允许您执行此操作。您必须编写一个解析器,然后手动构建邮件消息。不过,这并不难做到。这是电子邮件的结构:
首先,您将拥有看起来像 HEADER-NAME : CONTENT 的标头,并且标头将以 /r/n 结尾,后面不跟空格字符。如果标头具有 /r/n ,则意味着标头的值将在下一行继续。对于 Content-Transfer-Encoding,您可能需要对消息正文中的字节编码(quoted-printable 或 base64)进行解码。在标头之后,您将看到电子邮件正文本身,它与标头之间通过额外的行 (\r\n\r\n) 分隔。这可能只是文本或 HTML 或其他东西,在这种情况下,只需按字面解析它并根据传输编码对其进行解码。正文的可引用打印编码与标头略有不同,因此请在 RFC 2045、2046 和 2047 中阅读它。Base64 编码的内容在行之间将有一个换行符,但其他方面没有什么特别的。
如果你有执着什么东西,那你就得聪明一点。这些通常位于正文之后,并且将具有一个 Content-Type 标头,该标头将告诉您如何解码附件和有关附件的一些信息,以及可能提供有关附件的一些元数据的 Content-Disposition 标头。附件通常是基于 64 编码的。
最后,如果您在消息的内容类型标头下看到 multipart/mixed,则意味着您需要单独解析每个部分。它将为您提供一串字符,表示部件之间的边界。然后,每个部分都会有一个自己的 Content-Type 来说明它是什么,以及帮助描述该部分的其他标头。您必须解析出每个部分,然后手动解码它们,将附件写入内存流或文件。
完成所有这些后,您就可以用代码重新创建电子邮件。 NCL 团队曾讨论过以某种方式解决这一需求,但尚未做出任何决定,我也无法做出任何承诺。
作为示例,以下是一个 .eml 文件,其中包含一些自定义标题、两个备用视图(一个文本、一个 html)、一个用于 HTML 视图(图像)的链接资源以及一个 .txt 附件。我已经包含了一些 unicode,以便您可以看到编码机制。本文描述的示例公司、组织、产品、域名、电子邮件地址、徽标、人员、地点和事件均为虚构。无意或不应推断与任何真实的公司、组织、产品、域名、电子邮件地址、徽标、人员、地点或事件有任何关联。
X-Sender:[电子邮件受保护]
X-接收器:“戴夫·巴尼特”
X-SalesAgent: =?utf-8?B?VG9sbGV2c2VuLCBCasO4cm4=?=
MIME 版本:1.0
来自:[电子邮件受保护]
致:“戴夫·巴尼特”
回复: =?utf-8?Q?Tollevsen,_Bj=C3=B8rn?=
X 优先级:5
优先级:非紧急
重要性:低
日期: 2009年8月28日 13:03:40 -0700
主题:订单详情
内容类型:多部分/混合;边界=--boundary_2_1e984f0b-dc01-4739-a9c2-8302dc7c9c15
----boundary_2_1e984f0b-dc01-4739-a9c2-8302dc7c9c15
内容类型:多部分/替代;边界=--boundary_0_61ec80d2-1bf7-4554-922e-634e8e8a1067
----boundary_0_61ec80d2-1bf7-4554-922e-634e8e8a1067
内容类型:多部分/相关;类型=“文本/html”;边界=--boundary_1_e1f66bde-4086-4084-ad21-245b55a3d7a0
----boundary_1_e1f66bde-4086-4084-ad21-245b55a3d7a0
内容类型:text/html;字符集=utf-8
内容传输编码:base64
PEhUTUw+PEJPRFk+WW91ciBvcmRlciBoYXMgYmVlbiByZWNlaXZlZC48YnIvPk9y
ZGVyIDxhIGhyZWY9aHR0cDovL3d3dy5jb250b3NvLmNvbT5zdGF0dXM8L2E+PGJy
Lz48aW1nIHNyYz0iY2lkOmNvbXBhbnlMb2dvIiAvPjwvQk9EWT48L0hUTUw+
----boundary_1_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ScfhlKEZNa30bTa1106nIfGf4D+FP2g/B6aB4v0ttV0iOdLkWy3c
9sPMUEKSYXQkAMeCce3ArK0P9lDwB4a+Cl78O7DQPsvg/US5ubCO+uQZi7BmzN5n
m8lR/H0GonFeiUVFPMsZTpKhCrJQT5klJpKS2kle1/Pc1q5NgKtd4qpQg6jjyOTj
Fy5HvG9r8r/lvbyPOPg9+yT8PfgDomt6d4Q8P/2Na+IkEeoBL65lknUKygB5JGdM
B2xtIwTnrzVP4I/SU/DH9nLxVPrfg3wwmj6pc2zWck5v7q5JiZlYqBNI4GSi8gA8
dcV6nRWs85zCftOevN+0tz3lL3raLm196y0V72Oenw3lFNUVTwtNexbdO0Irkbd2
4ae629Xy2u9WFFFFeae0FFFFABRRRQB//9k=
----boundary_1_e1f66bde-4086-4084-ad21-245b55a3d7a0
------boundary_0_61ec80d2-1bf7-4554-922e-634e8e8a1067
内容类型:文本/纯文本;字符集=us-ascii
内容传输编码:quoted-printable
感谢您的订单。
----boundary_0_61ec80d2-1bf7-4554-922e-634e8e8a1067
------boundary_2_1e984f0b-dc01-4739-a9c2-8302dc7c9c15
内容类型:多部分/混合;边界=--boundary_3_5116e4dc-187a-4025-8b7f-9e74f87a79d1
----boundary_3_5116e4dc-187a-4025-8b7f-9e74f87a79d1
内容类型:应用程序/八位字节流;名称=订单.txt
内容传输编码:base64
内容处置:附件;文件名=订单.txt;创建日期=“28 日,星期五”
2009 年 8 月 13:03:40 -0700"
T3JkZXIgc3VtbWFyeToNCg0KV2lkZ2V0czogIDIwDQpTchJvY2tldHM6IDE1DQoN
ClRoYW5rIHlvdSBmb3IgeW91ciBvcmRlcg==
----boundary_3_5116e4dc-187a-4025-8b7f-9e74f87a79d1--
----boundary_2_1e984f0b-dc01-4739-a9c2-8302dc7c9c15--
There is no method in System.Net.Mail that allows you to do this. You'll have to write a parser and then build up the mail message manually. It's not that hard to do, though. Here's the structure of an email:
Fist you'll have headers that look like HEADER-NAME : CONTENT and a header will end with a /r/n that is NOT followed by a whitespace character. If a header has /r/n it means that the headers' value is continued on the next line. For Content-Transfer-Encoding, you'll need to potentially decode the byte encoding (quoted-printable or base64) in the message body. After the headers, you'll have the email body itself which is separated from the headers by an extra line (\r\n\r\n). This may just be text or HTML or something, in which case just parst it literally and decode it as per the transfer encoding. The quoted-printable encoding for the body is slightly different from the headers so read up on it in RFC 2045, 2046, and 2047. Base64 encoded content will have a newline character between lines but otherwise isn't anything special.
If you have attachments and stuff then you have to be a bit more clever. These are usually after the body and will have a Content-Type header that will tell you how to decode the attachment and some info about it as well as possibly a Content-Disposition header that provides some metadata about the attachment. Attachments are usually based64 encoded.
Finally, if you see a multipart/mixed under the message's content-type header, it means that you need to parse each part individually. It will give you a string of chars that denote the boundary between parts. Each part will then have a Content-Type of its own that says what it is as well as other headers that help describe that part. You'll have to parse out each of these parts and then decode them manually, writing attachments either to in-memory streams or to a file.
Once you have all of this, you can then re-create the email in code. There has been some talk on the NCL team of addressing this need somehow but nothing has been decided and I can't promise anything.
As an example, here's what a .eml file with some custom headres, two alternate views (one text, one html), a linked-resource for the HTML view that's an image, and a .txt attachment will look like. I've included some unicode so that you can see the encoding mechanisms. The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, places, or events is intended or should be inferred.
X-Sender: [email protected]
X-Receiver: "Dave Barnett"
X-SalesAgent: =?utf-8?B?VG9sbGV2c2VuLCBCasO4cm4=?=
MIME-Version: 1.0
From: [email protected]
To: "Dave Barnett"
Reply-To: =?utf-8?Q?Tollevsen,_Bj=C3=B8rn?=
X-Priority: 5
Priority: non-urgent
Importance: low
Date: 28 Aug 2009 13:03:40 -0700
Subject: order details
Content-Type: multipart/mixed; boundary=--boundary_2_1e984f0b-dc01-4739-a9c2-8302dc7c9c15
----boundary_2_1e984f0b-dc01-4739-a9c2-8302dc7c9c15
Content-Type: multipart/alternative; boundary=--boundary_0_61ec80d2-1bf7-4554-922e-634e8e8a1067
----boundary_0_61ec80d2-1bf7-4554-922e-634e8e8a1067
Content-Type: multipart/related; type="text/html"; boundary=--boundary_1_e1f66bde-4086-4084-ad21-245b55a3d7a0
----boundary_1_e1f66bde-4086-4084-ad21-245b55a3d7a0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: base64
PEhUTUw+PEJPRFk+WW91ciBvcmRlciBoYXMgYmVlbiByZWNlaXZlZC48YnIvPk9y
ZGVyIDxhIGhyZWY9aHR0cDovL3d3dy5jb250b3NvLmNvbT5zdGF0dXM8L2E+PGJy
Lz48aW1nIHNyYz0iY2lkOmNvbXBhbnlMb2dvIiAvPjwvQk9EWT48L0hUTUw+
----boundary_1_e1f66bde-4086-4084-ad21-245b55a3d7a0
Content-Type: image/jpeg; name=logo.jpg
Content-Transfer-Encoding: base64
Content-ID:
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYE
BAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQIC
AgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM
DAwMDAwMDAwMDAwMDAz/wAARCAAvAPUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEA
AAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIh
MUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6
Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZ
mqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx
8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREA
AgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEI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197d733NamRZbUVGNTD02qLvTvCL5HprD
T3XotVbZHnvxx/ZT+Hv7SK2p8aeF7HWprIjyLjfJb3KKN3yedEySFMsx2FtuTnGQ
DWP8I/2FfhL8DPEP9reGfBWm2epqVaO6uZZr6W3Zc4aJp3cxNyclNpPfNetUVdPO
cwhh/qkK81T/AJVKXL/4De34GdbhzKa2LWPq4WnKsvtuEXPTb3mr6eph/Eb4aaB8
XfCN3oPibSbLWtIvV2y21ym5c44ZT1VxnIZSGU8gg15V4O/4JtfBDwLrseo2Pw+0
ya5iUqq39zc6hDyMZMVxI8ZPoSuR1GDXuNFThc3x2Gpyo4atOEZbqMmk/VJ2ZWPy
DK8dVjiMbhqdScfhlKEZNa30bTa1106nIfGf4D+FP2g/B6aB4v0ttV0iOdLkWy3c
9sPMUEKSYXQkAMeCce3ArK0P9lDwB4a+Cl78O7DQPsvg/US5ubCO+uQZi7BmzN5n
m8lR/H0GOnFeiUVFPMsZTpKhCrJQT5klJpKS2kle1/Pc1q5NgKtd4qpQg6jjyOTj
Fy5HvG9r8r/lvbyPOPg9+yT8PfgDomt6d4Q8P/2Na+IkEeoBL65lknUKygB5JGdM
B2xtIwTnrzVP4I/sU/DH9nLxVPrfg3wwmj6pc2zWck5v7q5JiZlYqBNI4GSi8gA8
dcV6nRWs85zCftOevN+0tz3lL3raLm196y0V72Oenw3lFNUVTwtNexbdO0Irkbd2
4ae629Xy2u9WFFFFeae0FFFFABRRRQB//9k=
----boundary_1_e1f66bde-4086-4084-ad21-245b55a3d7a0--
----boundary_0_61ec80d2-1bf7-4554-922e-634e8e8a1067
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Thank you for your order.
----boundary_0_61ec80d2-1bf7-4554-922e-634e8e8a1067--
----boundary_2_1e984f0b-dc01-4739-a9c2-8302dc7c9c15
Content-Type: multipart/mixed; boundary=--boundary_3_5116e4dc-187a-4025-8b7f-9e74f87a79d1
----boundary_3_5116e4dc-187a-4025-8b7f-9e74f87a79d1
Content-Type: application/octet-stream; name=order.txt
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=order.txt; creation-date="Fri, 28
Aug 2009 13:03:40 -0700"
T3JkZXIgc3VtbWFyeToNCg0KV2lkZ2V0czogIDIwDQpTcHJvY2tldHM6IDE1DQoN
ClRoYW5rIHlvdSBmb3IgeW91ciBvcmRlcg==
----boundary_3_5116e4dc-187a-4025-8b7f-9e74f87a79d1--
----boundary_2_1e984f0b-dc01-4739-a9c2-8302dc7c9c15--