ng.Point16 460this.labelp.Name labelpthis.labelp.Size new System.Drawing.Size87 16this.labelp.TabIndex 34this.labelp.Text 正在发送邮件:this.labelp.Visible false//// labelTxt//this.labelTxt.Location new System.Drawing.Point16 213this.labelTxt.Name labelTxtthis.labelTxt.Size new System.Drawing.Size64 16this.labelTxt.TabIndex 35this.labelTxt.Text 邮件内容://// labelMsg//this.labelMsg.Location new System.Drawing.Point16 515this.labelMsg.Name labelMsgthis.labelMsg.Size new System.Drawing.Size87 18this.labelMsg.TabIndex 36this.labelMsg.Text 协议信息查看://// listBoxMsg//this.listBoxMsg.ItemHeight 12this.listBoxMsg.Location new System.Drawing.Point99 484this.listBoxMsg.Name listBoxMsgthis.listBoxMsg.ScrollAlwaysVisible truethis.listBoxMsg.Size new System.Drawing.Size429 88this.listBoxMsg.TabIndex 37//// gbBox1//this.gbBox1.Controls.Addthis.tBpwdthis.gbBox1.Controls.Addthis.labelPwdthis.gbBox1.Controls.Addthis.tBUserthis.gbBox1.Controls.Addthis.labelUserthis.gbBox1.Controls.Addthis.tBSrvthis.gbBox1.Controls.Addthis.labelSrvthis.gbBox1.Location new System.Drawing.Point18 8this.gbBox1.Name gbBox1this.gbBox1.Size new System.Drawing.Size510 80 this.gbBox1.TabIndex 38 this.gbBox1.TabStop false this.gbBox1.Text 服务器及其认证 // // gbBox2 // this.gbBox2.Controls.Addthis.tBRev this.gbBox2.Controls.Addthis.labelRev this.gbBox2.Controls.Addthis.tBSend this.gbBox2.Controls.Addthis.labelSender this.gbBox2.Controls.Addthis.labelsubject this.gbBox2.Controls.Addthis.tBSubject this.gbBox2.Location new System.Drawing.Point18 96 this.gbBox2.Name gbBox2 this.gbBox2.Size new System.Drawing.Size510 106 this.gbBox2.TabIndex 39 this.gbBox2.TabStop false this.gbBox2.Text 信封 // // Form1 // this.AutoScaleBaseSize new System.Drawing.Size6 14 this.ClientSize new System.Drawing.Size544 581 this.Controls.Addthis.gbBox2 this.Controls.Addthis.gbBox1 this.Controls.Addthis.listBoxMsg this.Controls.Addthis.labelTxt this.Controls.Addthis.pb1 this.Controls.Addthis.btnSend this.Controls.Addthis.tBMailText this.Controls.Addthis.labelp this.Controls.Addthis.labelMsg this.FormBorderStyle System.Windows.Forms.FormBorderStyle.FixedSingle this.MaximizeBox false this.Name Form1 this.Text 基于 ESMTP 的 EMAIL 发送程序 this.gbBox1.ResumeLayoutfalse this.gbBox1.PerformLayout this.gbBox2.ResumeLayoutfalse this.gbBox2.PerformLayout this.ResumeLayoutfalse this.PerformLayout endregion /// /// 应用程序的主入口点。
/// STAThread static void Main Application.Runnew Form1 TcpClient smtpSrv NetworkStream netStrm string CRLFrn private void WriteStreamstring strCmd strCmdCRLF byte bwSystem.Text.Encoding.Default.GetBytesstrCmd.ToCharArray netStrm.Write bw0bw.Length private string AuthStreamstring strCmd try bytebySystem.Text.Encoding.Default.GetBytesstrCmd.ToCharArray strCmdConvert.ToBase64Stringby catchException ex return ex.ToString return strCmd private void btnSend_Clickobject sender System.EventArgs e listBoxMsg.Items.Cleartry string data pb1.Visibletrue labelp.Visibletrue pb1.Value0 //建立与 SMTP 服务器的连接 smtpSrvnew TcpClient tBSrv.Text25 //获取一个网络流对象,以便通过网络连接来发送和接收数据 netStrmsmtpSrv.GetStream //生成一个 StreamReader 对象,用于从流中读取数据 StreamReader rdStrmnew StreamReadersmtpSrv.GetStream //向服务器发送 EHLO Local,请求建立连接 WriteStreamEHLO Local //读取服务器返回的信息,并写入信息列表中 listBoxMsg.Items.AddrdStrm.ReadLine pb1.Value //向服务器发送 AUTH LOGIN,请求认证 WriteStreamAUTH LOGIN listBoxMsg.Items.AddrdStrm.ReadLine pb1.Value datatBUser.Text //转换为 Base64 编码格式 dataAuthStreamdata //向服务器发送用户名 WriteStreamdata listBoxMsg.Items.AddrdStrm.ReadLine pb1.Value datatBpwd.Text //转换密码为 Base64 编码格式,且传送给服务器 dataAuthStreamdata WriteStreamdata listBoxMsg.Items.AddrdStrm.ReadLine pb1.Value //开始发送 EMAIL 的信封 //发信人的 EMAIL 地址 dataMAIL FROM: WriteStreamdata listBoxMsg.Items.AddrdStrm.ReadLine pb1.Value //收信人的 EMAIL 地址 dataRCPT TO: WriteStreamdata listBoxMsg.Items.AddrdStrm.ReadLinepb1.Value//开始发送数据WriteStreamDATAlistBoxMsg.Items.AddrdStrm.ReadLinepb1.Value//开始发送邮件的首部信息dataDate:DateTime.Now //发送日期WriteStreamdatapb1.Value//发送邮件发送者信息dataFrom:tBSend.TextWriteStreamdatapb1.Value//发送邮件接收者信息dataTO:tBRev.TextWriteStreamdatapb1.Value//发送邮件的主题dataSUBJECT:tBSubject.TextWriteStreamdatapb1.Value//发送回复地址dataReply-TO:tBSend.TextWriteStreamdatapb1.Value//发送一个空行,表示首部结束,开始正文发送WriteStreampb1.Value//发送邮件正文WriteStreamtBMailText.Textpb1.Value ,表示邮件内容结束//发送“.”WriteStream.pb1.ValuelistBoxMsg.Items.AddrdStrm.ReadLine//发送断开连接命令WriteStreamQUITpb1.ValuelistBoxMsg.Items.AddrdStrm.ReadLinenetStrm.CloserdStrm.Closepb1.Visiblefalselabelp.VisiblefalseMessageBox.Show邮件发送成功!成功 catch Exception ex MessageBox.Showex.ToString操作错误!
上一篇:
微型计算机系统的组成
下一篇:
初中团支部学期工作总结