在进行邮箱设置过程中,主要是“接收邮件(POP3)” 和“发送邮件(SMTP)”的设置,现将几个常用邮箱的地址汇总如下:
gmail邮箱:POP3(pop.gmail.com),SMTP(smtp.gmail.com);
homail邮箱:不提供pop3服务,是通过Http收发email;
msn邮箱:POP3(pop3.email.msn.com),SMTP(smtp.email.msn.com);
263.net邮箱:POP3(263.net),SMTP(smtp.263.net);
x263.net邮箱:POP3(pop.x263.net),SMTP(smtp.x263.net);
263.net.cn邮箱:POP3(263.net.cn),SMTP(263.net.cn);
yahoo.com.cn邮箱:POP3(pop.mail.yahoo.com.cn),SMTP(smtp.mail.yahoo.com.cn);
yahoo.com邮箱:POP3(pop.mail.yahoo.com),SMTP(smtp.mail.yahoo.com);
sohu邮箱:POP3(pop3.sohu.com),SMTP(smtp.sohu.com);
sina邮箱:POP3(pop3.sina.com.cn),SMTP(smtp.sina.com.cn);
163.com邮箱:POP3(pop.163.com),SMTP(smtp.163.com);
163.net邮箱:POP3(pop.163.net),SMTP(smtp.163.net);
sh163.net邮箱:POP3(mail.sh163.net),SMTP(mail.sh163.net);
21cn.net邮箱:POP3(pop.21cn.net),SMTP(smtp.21cn.net);
online.sh.cn邮箱:POP3(pop.citiz.net),SMTP(smtp.citiz.net);
chinaren.com邮箱:POP3(pop.chinaren.com),SMTP();
tom.com邮箱:POP3(pop.tom.com),SMTP(smtp.tom.com);
foxmail.com.cn邮箱:POP3(pop.foxmail.com.cn),SMTP(smtp.foxmail.com.cn);
etang.com邮箱:POP3(pop.etang.com),SMTP(smtp.etang.com);
netease.com邮箱:POP3(pop.netease.com),SMTP(smtp.netease.com)。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace 邮件接收
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public TcpClient Server;//TCP客户端连接
public NetworkStream NetStrm;//网络访问
public StreamReader RdStrm;
public string Data;
public byte[] szData;
public string CRLF = "/r/n";
private void Form1_Load(object sender, EventArgs e)
{
PopServer.Text = "pop.163.com";
Username.Text = "*****";//邮箱用户名
Password.Text = "*****";//邮箱密码
}
//连接
private void button1_Click(object sender, EventArgs e)
{
//将光标置为等待状态
Cursor cr = Cursor.Current;
//光标等待状态
Cursor.Current = Cursors.WaitCursor;
//用110端口新建POP3服务器连接(服务器端口号)
Server = new TcpClient(PopServer.Text, 110);
//状态
Status.Items.Clear();
try
{
//初始化=用于返回和接收数据
NetStrm = Server.GetStream();
//发送接收的数据
RdStrm = new StreamReader(Server.GetStream());
//流中第一行
Status.Items.Add(RdStrm.ReadLine());
string s = Status.Items[0].ToString();
int ssss = Status.Items.Count;
string ss = Status.Items[0].ToString();
//登录服务器过程
Data = "USER " + Username.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());
Data = "PASS " + Password.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());
//向服务器发送STAT命令,从而取得邮箱的相关信息:邮件数量和大小
Data = "STAT" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());
//改变按钮的状态
Connect.Enabled = false;
Disconnect.Enabled = true;
Retrieve.Enabled = true;
//将光标置回原来的状态
Cursor.Current = cr;
}
catch (InvalidOperationException err)
{
Status.Items.Add("Error: " + err.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
//将光标置为等待状态
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
//向服务器发送QUIT命令从而结束和POP3服务器的会话
Data = "QUIT" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());
//断开连接
NetStrm.Close();
RdStrm.Close();
//改变按钮的状态
Connect.Enabled = true;
Disconnect.Enabled = false;
Retrieve.Enabled = false;
//将光标置回原来的状态
Cursor.Current = cr;
}
//邮件接收
private void button3_Click(object sender, EventArgs e)
{
//将光标置为等待状态
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
string szTemp;
richTextBox1.Clear();
try
{
//根据邮件编号从服务器获得相应邮件
Data = "RETR " + MailNum.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
szTemp = RdStrm.ReadLine();
if (szTemp[0] != '-')
{
//不断地读取邮件内容,只到结束标志:英文句号
while (szTemp != ".")
{
richTextBox1.Text += szTemp;
szTemp = RdStrm.ReadLine();
}
//若BackupChBox未选中,则收取邮件后,删除保留在服务器上的邮件
if (BackupChBox.Checked == false)
{
Data = "DELE" + MailNum.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
Status.Items.Add(RdStrm.ReadLine());
}
}
else
{
Status.Items.Add(szTemp);
}
//将光标置回原来的状态
Cursor.Current = cr;
}
catch (InvalidOperationException err)
{
Status.Items.Add("Error: " + err.ToString());
}
}
}
}