问题是接收过来如何实现MIME解码,否则全是乱码

解决方案 »

  1.   

    看System.Web.Services.Protocols 命名空间,里面有 Mime相关的类
      

  2.   

    mime's encoding method is base64, you can get the begining,and get the code and decode it
      

  3.   

    email的编码有两种,base64和qb编码,还要识别他的信件头,有点麻烦的,在网上找一下资料吧,
      

  4.   

    我也有同样地问题得不到解决,还有charset的问题,html邮件显示的问题。希望能有英雄豪杰拔刀相助!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      

  5.   

    送我一份吧?
    [email protected]
      

  6.   

    如果是中文出现乱码的问题,可能RdStrm是这样定义的:RdStrm=new StreamReader(NetStrm),这样使用的编码是默认的UTF-8,这样定义RdStrm=new StreamReader(NetStrm,System.Text.Encoding.GetEncoding("gb2312"))可以解决中文的乱码问题。
        如果是要处理MIME数据,这可能需要专业人员来处理。
      

  7.   

    换成这句RdStrm=new StreamReader(NetStrm,System.Text.Encoding.GetEncoding("gb2312"))也是乱码吗?
      

  8.   

    我也要一份
    [email protected]
      

  9.   

    我根据你的代码写了一段代码,测试没有问题,改成下面这样看看,//根据邮件编号从服务器获得相应邮件
    string Data = "RETR "+ MailNum.Text+CRLF;
    byte[] szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
    NetStrm.Write(szData,0,szData.Length);
    StreamReader RdStrm=new StreamReader(NetStrm,System.Text.Encoding.GetEncoding("gb2312"));
    string szTemp = RdStrm.ReadLine();
    string ss="";
    if (szTemp.IndexOf("+OK")>=0)
    {
    while ((szTemp=RdStrm.ReadLine())!=".")
    {
    ss+=szTemp;
    }
    MessageBox.Show(ss);
      

  10.   

    我想知道的是
    如何取得邮件的附件数,和分别取得附件的base64编码。
    最好能用正则表达式。
      

  11.   

    奇怪了。我的怎么还是老样子,我给你整段的代码,你帮我看看好吗?非常感谢:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Net;
    using System.Net.Sockets;
    using System.IO;namespace MailReceiver
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.Label label5;
    private System.Windows.Forms.Label label6;
    private System.Windows.Forms.TextBox PopServer;
    private System.Windows.Forms.TextBox Username;
    private System.Windows.Forms.TextBox Password;
    private System.Windows.Forms.RichTextBox Message;
    private System.Windows.Forms.TextBox MailNum;
    private System.Windows.Forms.ListBox Status;
    private System.Windows.Forms.Button Connect;
    private System.Windows.Forms.Button Disconnect;
    private System.Windows.Forms.Button Retrieve;
    private System.Windows.Forms.CheckBox BackupChBox; public TcpClient Server;
    public NetworkStream NetStrm;
    public StreamReader  RdStrm;
    public string Data;
    public byte[] szData;
    public string CRLF = "\r\n"; /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }
      

  12.   

    #region Windows Form Designer generated code
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.label3 = new System.Windows.Forms.Label();
    this.label4 = new System.Windows.Forms.Label();
    this.label5 = new System.Windows.Forms.Label();
    this.label6 = new System.Windows.Forms.Label();
    this.PopServer = new System.Windows.Forms.TextBox();
    this.Username = new System.Windows.Forms.TextBox();
    this.Password = new System.Windows.Forms.TextBox();
    this.MailNum = new System.Windows.Forms.TextBox();
    this.Connect = new System.Windows.Forms.Button();
    this.Disconnect = new System.Windows.Forms.Button();
    this.Retrieve = new System.Windows.Forms.Button();
    this.Message = new System.Windows.Forms.RichTextBox();
    this.Status = new System.Windows.Forms.ListBox();
    this.BackupChBox = new System.Windows.Forms.CheckBox();
    this.SuspendLayout();
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(16, 16);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(112, 23);
    this.label1.TabIndex = 0;
    this.label1.Text = "POP3 服务器地址:";
    this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
    // 
    // label2
    // 
    this.label2.Location = new System.Drawing.Point(16, 48);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(112, 16);
    this.label2.TabIndex = 1;
    this.label2.Text = "用户名:";
    this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
    // 
    // label3
    // 
    this.label3.Location = new System.Drawing.Point(16, 80);
    this.label3.Name = "label3";
    this.label3.Size = new System.Drawing.Size(112, 16);
    this.label3.TabIndex = 2;
    this.label3.Text = "密码:";
    this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
    // 
    // label4
    // 
    this.label4.Location = new System.Drawing.Point(8, 272);
    this.label4.Name = "label4";
    this.label4.Size = new System.Drawing.Size(72, 23);
    this.label4.TabIndex = 3;
    this.label4.Text = "邮件编号:";
    this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
    // 
    // label5
    // 
    this.label5.Location = new System.Drawing.Point(8, 112);
    this.label5.Name = "label5";
    this.label5.Size = new System.Drawing.Size(100, 16);
    this.label5.TabIndex = 4;
    this.label5.Text = "信息:";
    this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
    // 
    // label6
    // 
    this.label6.Location = new System.Drawing.Point(8, 304);
    this.label6.Name = "label6";
    this.label6.Size = new System.Drawing.Size(100, 16);
    this.label6.TabIndex = 5;
    this.label6.Text = "状态:";
    this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
    // 
    // PopServer
    // 
    this.PopServer.Location = new System.Drawing.Point(136, 16);
    this.PopServer.Name = "PopServer";
    this.PopServer.Size = new System.Drawing.Size(168, 21);
    this.PopServer.TabIndex = 0;
    this.PopServer.Text = "";
    // 
    // Username
    // 
    this.Username.Location = new System.Drawing.Point(136, 48);
    this.Username.Name = "Username";
    this.Username.Size = new System.Drawing.Size(168, 21);
    this.Username.TabIndex = 1;
    this.Username.Text = "";
    // 
    // Password
    // 
    this.Password.Location = new System.Drawing.Point(136, 80);
    this.Password.Name = "Password";
    this.Password.PasswordChar = '*';
    this.Password.Size = new System.Drawing.Size(168, 21);
    this.Password.TabIndex = 2;
    this.Password.Text = "";
    // 
    // MailNum
    // 
    this.MailNum.Location = new System.Drawing.Point(88, 272);
    this.MailNum.Name = "MailNum";
    this.MailNum.Size = new System.Drawing.Size(40, 21);
    this.MailNum.TabIndex = 4;
    this.MailNum.Text = "";
    // 
    // Connect
    // 
    this.Connect.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.Connect.Location = new System.Drawing.Point(320, 24);
    this.Connect.Name = "Connect";
    this.Connect.Size = new System.Drawing.Size(75, 24);
    this.Connect.TabIndex = 7;
    this.Connect.Text = "连接";
    this.Connect.Click += new System.EventHandler(this.Connect_Click);
    // 
    // Disconnect
    // 
    this.Disconnect.Enabled = false;
    this.Disconnect.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.Disconnect.Location = new System.Drawing.Point(320, 64);
    this.Disconnect.Name = "Disconnect";
    this.Disconnect.Size = new System.Drawing.Size(75, 24);
    this.Disconnect.TabIndex = 8;
    this.Disconnect.Text = "断开连接";
    this.Disconnect.Click += new System.EventHandler(this.Disconnect_Click);
    // 
    // Retrieve
    // 
    this.Retrieve.Enabled = false;
    this.Retrieve.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
    this.Retrieve.Location = new System.Drawing.Point(320, 272);
    this.Retrieve.Name = "Retrieve";
    this.Retrieve.Size = new System.Drawing.Size(72, 24);
    this.Retrieve.TabIndex = 9;
    this.Retrieve.Text = "收取邮件";
    this.Retrieve.Click += new System.EventHandler(this.Retrieve_Click);
    // 
    // Message
    // 
    this.Message.Location = new System.Drawing.Point(8, 136);
    this.Message.Name = "Message";
    this.Message.Size = new System.Drawing.Size(384, 128);
    this.Message.TabIndex = 3;
    this.Message.Text = "";
    // 
    // Status
    // 
    this.Status.ItemHeight = 12;
    this.Status.Location = new System.Drawing.Point(8, 328);
    this.Status.Name = "Status";
    this.Status.Size = new System.Drawing.Size(384, 52);
    this.Status.TabIndex = 6;
    // 
    // BackupChBox
    // 
    this.BackupChBox.Location = new System.Drawing.Point(144, 272);
    this.BackupChBox.Name = "BackupChBox";
    this.BackupChBox.Size = new System.Drawing.Size(160, 24);
    this.BackupChBox.TabIndex = 5;
    this.BackupChBox.Text = "在邮件服务器上保留备份";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(400, 389);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.BackupChBox,
      this.Status,
      this.Message,
      this.Retrieve,
      this.Disconnect,
      this.Connect,
      this.MailNum,
      this.Password,
      this.Username,
      this.PopServer,
      this.label6,
      this.label5,
      this.label4,
      this.label3,
      this.label2,
      this.label1});
    this.MaximizeBox = false;
    this.Name = "Form1";
    this.Text = "POP3邮件接收程序";
    this.ResumeLayout(false); }
    #endregion
      

  13.   

    dy_2000_abc(芝麻开门):
        首先非常感谢!!!!!!!!!!!!!
    我收了163的邮件可以了。
    我是自己有个邮件服务器,我直接在OUTLOOK EXPRESS 发送邮件,然后才用这个来收,就出现了一些乱码如:
    +OK 1301 octetsMessage-ID: <[email protected]>From: =?gb2312?B?ssy80czO?= <[email protected]>To: <[email protected]>Subject: teatDate: Mon, 9 Dec 2002 16:46:00 +0800MIME-Version: 1.0Content-Type: multipart/alternative; boundary="----=_NextPart_000_0007_01C29FA2.74799A80"X-Priority: 3X-MSMail-Priority: NormalX-Mailer: Microsoft Outlook Express 6.00.2600.0000X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000This is a multi-part message in MIME format.------=_NextPart_000_0007_01C29FA2.74799A80Content-Type: text/plain; charset="gb2312"Content-Transfer-Encoding: base64YWRmYXNkICAguLO4+CAgyau1qLj2IA0K------=_NextPart_000_0007_01C29FA2.74799A80Content-Type: text/html; charset="gb2312"Content-Transfer-Encoding: base64PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwvL0VOIj4NCjxIVE1MPjxIRUFEPg0KPE1FVEEgaHR0cC1lcXVpdj1Db250ZW50LVR5cGUgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PWdiMjMxMiI+DQo8TUVUQSBjb250ZW50PSJNU0hUTUwgNi4wMC4yNjAwLjAiIG5hbWU9R0VORVJBVE9SPg0KPFNUWUxFPjwvU1RZTEU+DQo8L0hFQUQ+DQo8Qk9EWSBiZ0NvbG9yPSNmZmZmZmY+DQo8RElWPjxGT05UIHNpemU9Mj5hZGZhc2QmbmJzcDsmbmJzcDsguLO4+CZuYnNwOyDJq7WouPYgPC9GT05UPjwvRElWPjwvQk9EWT48L0hUTUw+DQo=------=_NextPart_000_0007_01C29FA2.74799A80--这个可能就是要处理MIME数据的问题吧。
      

  14.   

    我对pop3了解甚少,从显示的内容看,好像是base64编码的MIME数据,如果传输的是字符,你可以使用base64解码(Convert.Tobase64String(byte[] b))试试,要是图片或者音乐,那就无能为力了。