首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于邮件的解码有关问题,RETR,POP3,邮件,附件,解码,邮件接收

2012-01-15 
关于邮件的解码问题,RETR,POP3,邮件,附件,解码,邮件接收大家好,我C#.net(.NETFramework2.0)中做一个邮件接

关于邮件的解码问题,RETR,POP3,邮件,附件,解码,邮件接收
大家好,我C#.net(.NET   Framework   2.0)中做一个邮件接收的程序。
利用里面的命名空间:
using   System.Net;
using   System.Net.Mail;
using   System.Net.Mime;
using   System.Net.Sockets;
using   System.IO;
using   System.Threading;

还使用了这些:
……
TcpClient   tcpcnt=   new   TcpClient(txtPop3Server.Text,   110);
……
NetworkStream   ns   =   null;
ns   =   tcpcnt.GetStream();
StreamReader   sr   =   new   StreamReader(ns);
      ……
                         
现在遇到了问题,请大家来帮我看看。

我通过POP3中的RETR指令从我自己的邮箱(luyangfree@126.com)中接收里面
的邮件。
我的邮件里的内容是:
邮件的主题是:attachment
邮件的内容是:This   is   txt   attachment.
邮件的附件是一个文本文件(ERR.txt),
文本文件里面的内容是:-ERR   Unable   to   log   on


以下是我邮件接收返回的信息:


  +OK   2773   octets
Received:   from   mu-out-0910.google.com   (unknown   [209.85.134.191])
by   mx15   (Coremail)   with   SMTP   id   wKjSpLDb7_LgJ+FFePnUEA==.40756S2;
Sun,   25   Feb   2007   14:08:33   +0800   (CST)
Received:   by   mu-out-0910.google.com   with   SMTP   id   g7so877445muf
                for   <luyangfree@126.com> ;   Sat,   24   Feb   2007   22:08:29   -0800   (PST)
DKIM-Signature:   a=rsa-sha1;   c=relaxed/relaxed;
                d=gmail.com;   s=beta;
                h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type;
                b=R22Hv9U/n2fRhBbb/cMdNqp8eW80Q75Gir/xQON0UU1QpXi3iRLYX6ibHyItAQ/MQG4QBrfKj6PcbtcUTQ23TYRSHT8CacRXO0OY2uN+FkF51SMSdKWwVqSPtk+obZn+V4zjqFn1W3sU41pQ4kzLekPDhhRmJGJO6Z9sv8LXHvY=
DomainKey-Signature:   a=rsa-sha1;   c=nofws;
                d=gmail.com;   s=beta;
                h=received:message-id:date:from:to:subject:mime-version:content-type;
                b=kZEGW9fKxQLYjlL7VMI/WzpcZOY54q4IfVI7IWezg96dARAtpAj3fpl/NuySfuDhE3GOPxv7Tv79ClOKrKzwALURE4oJhoDEY/oyl7PeOldFYJzzk0oB3/ZXAJz6oOyvBfzXcUAN0F6q/AlFClV0cMLqB576uD0aV3/NaKDKmhI=
Received:   by   10.82.135.13   with   SMTP   id   i13mr1228808bud.1172383708921;
                Sat,   24   Feb   2007   22:08:28   -0800   (PST)
Received:   by   10.82.189.3   with   HTTP;   Sat,   24   Feb   2007   22:08:28   -0800   (PST)
Message-ID:   <f9a9dfa70702242208j75854c3er4c40ab858c11414e@mail.gmail.com>
Date:   Sun,   25   Feb   2007   14:08:28   +0800
From:   "=?GB2312?B?wr3R7g==?= "   <luyangfree@gmail.com>
To:   luyangfree@126.com
Subject:   attachment
MIME-Version:   1.0
Content-Type:   multipart/mixed;  
boundary= "----=_Part_49134_11090661.1172383708899 "
X-Coremail-Antispam:   1U3Yxn0WfASr-VFAUDIcSsGvfJT3xCjnVCjjxCrMxkI7II2jI
8vz4v_Cr0_Zr1lYx0Ex4A2jsIE14v26r4UJVWxJr1l6VACY4xI67k04243AwACY4xI67k0
4243AVC20s07MxkFs20EbsIEYx1lYx0E2Ix0cI8IcVAFwI0_Jrv_JF1lc2xSY4AK6IIF6r


47M7AC8VAFwI0_Jr0_Gr1l7I0Y6sxI4wAYFVCjjxCrM7CIcVAFz4kK6r1j6r18Mc02F40E
4c8EcI0Er2xKeI8DMc02F40EFcxC0VAKzVAqx4xG6I80ewAYjsxI4VWUJjkaLaAFLSUrUU
UUUjvjm3AaLaJ3UjIFyTuYvjxUUjg4DUUUUUAaLaJ3U

------=_Part_49134_11090661.1172383708899
Content-Type:   multipart/alternative;  
boundary= "----=_Part_49135_5869753.1172383708899 "

------=_Part_49135_5869753.1172383708899
Content-Type:   text/plain;   charset=ISO-8859-1;   format=flowed
Content-Transfer-Encoding:   7bit
Content-Disposition:   inline

This   is   txt   attachment.

------=_Part_49135_5869753.1172383708899
Content-Type:   text/html;   charset=ISO-8859-1
Content-Transfer-Encoding:   7bit
Content-Disposition:   inline

This   is   txt   attachment.

------=_Part_49135_5869753.1172383708899--

------=_Part_49134_11090661.1172383708899
Content-Type:   text/plain;   name= "ERR.txt "
Content-Transfer-Encoding:   base64
Content-Disposition:   attachment;   filename= "ERR.txt "
X-Attachment-Id:   f_eyl2zd46

LUVSUiBVbmFibGUgdG8gbG9nIG9u
------=_Part_49134_11090661.1172383708899--


请问,我应该怎么样做,才能实现接收回来的邮件内容的正常显示,
邮件附件的正确接收?




[解决办法]
这是 base64 编码,其中下面的行是分隔符

------=_Part_49135_5869753.1172383708899--
[解决办法]
------=_Part_49134_11090661.1172383708899
Content-Type: text/plain; name= "ERR.txt "
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename= "ERR.txt "
X-Attachment-Id: f_eyl2zd46

LUVSUiBVbmFibGUgdG8gbG9nIG9u
------=_Part_49134_11090661.1172383708899--
这是一个段。
必须找到这个段 段头信息和段体信息之间,有一个空行。
头信息说明,这是一个附件。内容是文本型,附件名为ERR.txt 传输编码是base64
头信息必须解析,不然不能正确解析附件体

热点排行