C# 用NetworkStream接收Email 不同邮件服务器的邮件内容解码


最近在开发一个邮件管理模块,遇到了个非常棘手的问题,想在此向各位前辈请教。好吧,下面直接进入正题。

在从服务器上把接收到的邮件抓取到自己的系统里,用C#的NetworkStream。可是在抓取的时候,发现不同邮件邮件服务器发送过来的邮件是邮件内容格式不一样,比如从126邮箱上抓取的,可是qq和gmail发过来的邮件内容格式是不一样的,编码也不一样。

比如:qq的


 This is a multi-part message in MIME format.

------=_NextPart_541CD1E4_08F79BC0_6F260227
Content-Type: text/plain;
    charset="utf-8"
Content-Transfer-Encoding: base64

5q2j5paH4oCN

------=_NextPart_541CD1E4_08F79BC0_6F260227
Content-Type: text/html;
    charset="utf-8"
Content-Transfer-Encoding: base64

PGRpdj48c3BhbiBzdHlsZT0iZm9udC1mYW1pbHk6ICdsdWNpZGEgR3JhbmRlJywgVmVyZGFu
YSwgJ01pY3Jvc29mdCBZYUhlaSc7IGZvbnQtc2l6ZTogMTJweDsgbGluZS1oZWlnaHQ6IG5v
cm1hbDsgdGV4dC1hbGlnbjogcmlnaHQ7IHdoaXRlLXNwYWNlOiBub3dyYXA7IGJhY2tncm91
bmQtY29sb3I6IHJnYigyMzksIDI0NSwgMjUxKTsiPuato+aWhzxzcGFuIGlkPSJfZWRpdG9y
X2Jvb2ttYXJrX3N0YXJ0XzEiIHN0eWxlPSJkaXNwbGF5OiBub25lOyBsaW5lLWhlaWdodDog
MHB4OyI+4oCNPC9zcGFuPjwvc3Bhbj48L2Rpdj4=

------=_NextPart_541CD1E4_08F79BC0_6F260227--

gmail的


 --_470a4591-c5b7-402c-8312-0fc353ea79c1_
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: base64

0ru49snxw9jXqNK1oaMgCQkgCSAgIAkJICA=

--_470a4591-c5b7-402c-8312-0fc353ea79c1_
Content-Type: text/html; charset="gb2312"
Content-Transfer-Encoding: base64

PGh0bWw+DQo8aGVhZD4NCjxzdHlsZT48IS0tDQouaG1tZXNzYWdlIFANCnsNCm1hcmdpbjowcHg7
DQpwYWRkaW5nOjBweA0KfQ0KYm9keS5obW1lc3NhZ2UNCnsNCmZvbnQtc2l6ZTogMTJwdDsNCmZv
bnQtZmFtaWx5Os6iyO3RxbraDQp9DQotLT48L3N0eWxlPjwvaGVhZD4NCjxib2R5IGNsYXNzPSdo
bW1lc3NhZ2UnPjxkaXYgZGlyPSdsdHInPtK7uPbJ8cPY16jStaGjIAkJIAkgICAJCSAgPC9kaXY+
PC9ib2R5Pg0KPC9odG1sPg==

--_470a4591-c5b7-402c-8312-0fc353ea79c1_--

问题的重点是,我们可能会接收到各种不同的服务器邮件,特别是国外的,我又穷举不了。格式编码不同,我应该怎么样去解决这个问题,有没有谁遇到过同样的问题啊?

解码 c# email

灼热冰淇淋 10 years, 1 month ago

有现成的库
OpenPop.NET

昔日的小伙伴 answered 10 years, 1 month ago

Your Answer