电子邮件系统中的协议主要有RFC822,SMTP,POP,IMAP,MIME五种协议,这里将介绍一个简单的基于POP3协议的邮件接收程序。
The main protocols of Email System is RFC822,SMTP,POP,IMAP ,MIME five kind of protocols, here I want to introduce a simple program of reciving email based on POP protocol.
POP3协议是一个客户端/服务器协议,他为实现客户端和服务端通信定义了一套会话命令,客户机通过调用这些命令来处理存放在POP3服务器中的电子邮件,具体实现对电子邮件的接收,删除等具体操作。这些命令及其说明如下:
POP3 Protocol is a Client/Server protocol,It defines a set of commands to implement communication of Client and Server ,By calling these commands Client machine can deal with Email which storaged in POP3 Server, the specific implementation of an Email reciving,an Email deleting and other specific operations ,etc.These commands and their descriptions are as follow:
一个简单的用运用下面命令的例子:
String Data="PASS"+"你的密码"+"\r\n" ("\r\n" 是一个回车换行符)
byte[] szData=System.Text.Encoding.GetEncoding("gb2312") . GetVytes(Data.ToCharArray()) ;
TcpClient Server=new TcpClient("POP服务器IP地址",110);
NetworkStream Netstr=Server.GetStream();
Netstr.write(szData,0,szData.Length);
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;
using System.Text;
namespace 编写邮件接收程序
{
/// <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.TextBox POPServ;
private System.Windows.Forms.TextBox User;
private System.Windows.Forms.TextBox Passw;
private System.Windows.Forms.RichTextBox Message;
private System.Windows.Forms.Button ConnectBtn;
private System.Windows.Forms.Button DisconnectBtn;
private System.Windows.Forms.Button RetrieveBtn;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.StatusBar statusBar1;
public TcpClient Server;
//用以和服务器建立TCP连接
public NetworkStream NetStrm;
//客户机和服务器会话使用的数据流
public StreamReader RdStrm;
//用以操作数据流,从数据流中获取从服务器反馈的数据
public string Data;
public byte[] szData;
public string CRLF = "\r\n";
//回车换行符
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
//