基于某POP3与SMTP协议详情地邮件收发程序地开发文档格式.docx

上传人:b****3 文档编号:16802734 上传时间:2022-11-26 格式:DOCX 页数:23 大小:211.64KB
下载 相关 举报
基于某POP3与SMTP协议详情地邮件收发程序地开发文档格式.docx_第1页
第1页 / 共23页
基于某POP3与SMTP协议详情地邮件收发程序地开发文档格式.docx_第2页
第2页 / 共23页
基于某POP3与SMTP协议详情地邮件收发程序地开发文档格式.docx_第3页
第3页 / 共23页
基于某POP3与SMTP协议详情地邮件收发程序地开发文档格式.docx_第4页
第4页 / 共23页
基于某POP3与SMTP协议详情地邮件收发程序地开发文档格式.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

基于某POP3与SMTP协议详情地邮件收发程序地开发文档格式.docx

《基于某POP3与SMTP协议详情地邮件收发程序地开发文档格式.docx》由会员分享,可在线阅读,更多相关《基于某POP3与SMTP协议详情地邮件收发程序地开发文档格式.docx(23页珍藏版)》请在冰豆网上搜索。

基于某POP3与SMTP协议详情地邮件收发程序地开发文档格式.docx

它规定怎样将个人计算机连接到Internet的服务器和下载电子的电子协议。

它是因特网电子的第一个离线协议标准,POP3允许用户从服务器上把存储到本地主机(即自己的计算机)上,同时删除保存在服务器上的,而POP3服务器则是遵循POP3协议的接收服务器,用来接收电子的。

总的来说POP3协议是让用户把服务器上的信收到本地来所需要的一种协议。

本程序为一个基于SMTP和POP3协议的小型EMAIL收发程序,简单的实现了的收发功能。

二、算法流程图

USER

E-mail

用户操作

SMTP协议

POP3协议

邮件服务器

用户登录

用户信息

邮件信息

选择邮件

发送邮件

接收邮件

图1算法流程图

三、源代码

下面给出的是用登录程序的源代码:

usingSystem;

//导入名字空间

usingSystem.Collections.Generic;

//包含定义各种对象集合的接口和类

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

//包含表示ASCII等字符编码的类

usingSystem.Windows.Forms;

usingSystem.Net;

usingSystem.Net.Sockets;

usingSystem.IO;

namespaceMailSendOfRecive//命名空间

{

publicpartialclassForm3:

Form//定义类

publicstringConn,Uname,Pwd,Inf;

//定义用户名、密码

publicTcpClientServer;

//定义服务器

publicNetworkStreamNetStrm;

publicStreamReaderRdStrm;

publicBooleanBPass;

//定义BPass

publicstringData;

publicbyte[]szData;

publicstringCRLF="

\r\n"

;

//定义快捷键

publicForm2Sender;

publicForm3()//定义框架

InitializeComponent();

//初始化

}

privatevoidLogin_Click(objectsender,EventArgse)

Conn="

pop."

+textBox1.Text.Trim();

Uname=textBox2.Text.Trim();

//用户名

Pwd=textBox3.Text;

//密码

Server=newTcpClient(Conn,110);

//服务器

try

NetStrm=Server.GetStream();

RdStrm=newStreamReader(Server.GetStream(),System.Text.Encoding.Default);

RdStrm.ReadLine();

Data="

USER"

+Uname+CRLF;

szData=System.Text.Encoding.ASCII.GetBytes(Data);

//获取ASCII值

NetStrm.Write(szData,0,szData.Length);

//读取字符并返回

PASS"

+Pwd+CRLF;

Inf=RdStrm.ReadLine();

if(Inf.IndexOf("

+OK"

)>

-1)

BPass=true;

//布尔值设为真

Sender=newForm2(Uname,Pwd,textBox1.Text);

this.Hide();

Sender.Show();

elseif(Inf.IndexOf("

-OK"

-1)//判断索引

MessageBox.Show("

密码或者用户名错误"

"

用户验证"

);

//文本框显示信息

QUIT"

NetStrm.Write(szData,0,szData.Length);

//写入数据

catch(System.Exceptionex)

MessageBox.Show(ex.Message);

privatevoidForm3_Load(objectsender,EventArgse)//定义Form3_Load

下面是发送程序源代码

usingSystem.Collections;

usingSystem.Data.OleDb;

publicpartialclassForm1:

TcpClientsmtpSrv;

NetworkStreamnetStm;

//提供数据流

stringCRLF="

publicList<

MailInfo>

SMail=newList<

();

publicForm2fa;

publicstringUa,Pw,Sv;

publicForm1(Form2f,stringUN,stringPd,stringSR)//创建Form1

fa=f;

Ua=UN;

Pw=Pd;

Sv=SR;

publicvoidWriteStream(stringstrCmd)

strCmd+=CRLF;

//crlf表示结束

byte[]bw=System.Text.Encoding.Default.GetBytes(strCmd);

//将字符串转为字节数组

netStm.Write(bw,0,bw.Length);

//写入网络

privatestringAuthStream(stringstrCmd)//连接服务器输出字符串

byte[]by=System.Text.Encoding.Default.GetBytes(strCmd);

strCmd=Convert.ToBase64String(by);

//转换成base64编码

returnex.ToString();

returnstrCmd;

publicbooltryTran(refstringa)//定义布尔变量

stringb="

"

b=a;

byte[]outputb=Convert.FromBase64String(a);

//转换数据类型

a=Encoding.Default.GetString(outputb);

returntrue;

catch(System.Exceptionex)//显示错误

a=b;

returnfalse;

publicvoidWritInf(strings)//定义WritInf

tryTran(refs);

listBoxMsg.Items.Add(s);

privatevoidButtonSend_Click(objectsender,EventArgse)//定义ButtonSend_Click

listBoxMsg.Items.Clear();

//存放smtp服务器返回的信息

stringdata;

progressBar1.Visible=true;

progressBar1.Value=1;

smtpSrv=newTcpClient("

smtp."

+Sv,25);

//TextBoxSer.Text,25);

//连接smtp服务器

netStm=smtpSrv.GetStream();

//取得Networkstream对象,来发送接收数据

StreamReaderrdStrm=newStreamReader(smtpSrv.GetStream());

//产生StreamReader来读取数据流

WriteStream("

EHLOLocal"

//发送命令建立连接

progressBar1.Value++;

listBoxMsg.Items.Add("

输入用户名开始"

AUTHLOGIN"

//发送命令请求验证

listBoxMsg.Items.Add(rdStrm.ReadLine());

data=AuthStream(Ua);

//data);

//转换编码格式

WriteStream(data);

//发送用户名

data=AuthStream(Pw);

//发送

data="

MAILFROM:

<

+TextBoxSend.Text+"

>

//发件人地址

RCPTTO:

+TextBoxRev.Text+"

//收件人地址

DATA"

//数据

Date:

+System.DateTime.Now;

//日期

From:

+TextBoxSend.Text;

//发送者

To:

+TextBoxRev.Text;

//接收者

SUBJECT:

+textBoxSubject.Text;

//主题

Reply-To:

//发送回复地址

//表示首部结束,开始正文

WriteStream(textBoxMailText.Text);

."

//点表示容结束

//断开

//添加项

netStm.Close();

rdStrm.Close();

//释放资源

MailInfoi=newMailInfo();

i.sender=TextBoxSend.Text;

i.geter=TextBoxRev.Text;

i.Ttile=textBoxSubject.Text;

i.NeiRong=textBoxMailText.Text;

i.Datatime=DateTime.Now.ToString();

//将发送的消息送到SMail便于传个收件箱界面

SMail.Add(i);

发送成功"

成功"

//显示信息

MessageBox.Show(ex.ToString(),"

操作错误"

privatevoidForm1_FormClosed(objectsender,FormClosedEventArgse)

Application.Exit();

//终止所有程序

privatevoidbutton1_Click(objectsender,EventArgse)

//隐藏控件

fa.Show();

fa.GetSenMail(SMail);

privatevoidForm1_Load(objectsender,EventArgse)

下面是接收程序源代码

usingSystem.Net.Mail;

publicpartialclassForm2:

publicstringData,UsName,Pawd,InEmai;

publicbyte[]szData,other;

EMail=newList<

//链表类

DMail=newList<

SndMail=newList<

publicFileStreamfs;

publicintInfoID,BackId;

publicintDeleTxt=-1;

//声明写入流

DataTabledt=newDataTable();

//数据表了,类似于数据库,可以存放数据

publicForm2(stringUname,stringPwd,stringIEM)

InfoID=-1;

InEmai=IEM;

//"

+IEM;

UsName=Uname;

Pawd=Pwd;

Inint();

//为网格添加标题

dt.Columns.Add("

ID"

typeof(int));

主题"

typeof(string));

发件人"

//创建对象

时间"

含有附件"

typeof(Boolean));

privatevoidInint()//初始化节点

TreeNodeNode=treeView1.Nodes.Add("

Name"

归档系统"

Node.Nodes.Add("

Send"

发件箱"

Recove"

收件箱"

GuiDang"

归档"

//获取对象的集合

HuiShou"

回收站"

privatevoidShowInfo()

privatevoidbuttonCon_Click(objectsender,EventArgse)

//定义点击事件

Server=newTcpClient("

+InEmai,110);

//初始化服务器

RdStrm=newStreamReader(NetStrm,System.Text.Encoding.Default);

listBoxStatus.Items.Add(RdStrm.ReadLine());

//向列表添加项

+UsName+CRLF;

//textBoxUser.Text+CRLF;

szData=System.Text.Encoding.Default.GetBytes(Data);

//获取编码

+Pawd+CRLF;

//textBoxPwd.Text+CRLF;

//获取所有的的大小

STAT"

+CRLF;

stringst=RdStrm.ReadLine();

MessageBox.Show(st);

//显示消息框

listBoxStatus.Items.Add(st);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1