C#电子邮件客户端软件设计(开题报告+英文文献+答辩PPT) 第16页
  flag=true; 
   } 
   if(SendCommand(str)) 
   { 
    string RR=RecvResponse(); 
    //从返回的数据中截取前三位
    string RRCode=RR.Substring(0,3); 
    //然后用这前三位与哈希表中正确的回应码比较
    if(RightCodeHT[RRCode]!=null) 
    { 
     flag=true; 
    } 
    else 
    {
     flag=false; 
    } 
   } 
   else 
   { 
    flag=false; 
   } 
   return flag; 
  }
发送一组命令主要用于服务器验证的重载函数为:
private bool Dialog(string[] str,string errstr) 
  { 
   for(int i=0;i<str.Length;i++) 
   { 
    //循环调用单个的与服务器的交互过程
    if(!Dialog(str[i],"")) 
    { 
     return false; 
    } 
   } 
   return true; 
  }
8) 邮件发送程序 SendMail
这是整个程序的核心部分。具体的实现SMTP协议的程序正是通过它一步一步实现并最终实现发送简单邮件甚至带附件的邮件的功能。而它的实现是调用以上给出的各个函数的结果。以下就简单的通过几个SMTP命令的格式来实现
private bool SendEmail() 
  { 
   //连接网络 
   try 
   { 
    //建立一个TCP连接
    tc=new TcpClient(mailserver,mailserverport); 
   } 
   catch
   { 
    MessageBox.Show ("连接失败","请确认");
    return false; 
   } 
   //获取当前流的资料
   ns = tc.GetStream(); 
   SMTPCodeAdd(); 
   //验证网络连接是否正确 
   if(RightCodeHT[RecvResponse().Substring(0,3)]==null) 
   {
    return false; 
   } 
   string[] SendBuffer; 
   string SendBufferstr; 
   //进行SMTP验证 
   //具体的SMTP命令与代码的结合
   if(ESmtp) 
   { 
    SendBuffer=new String[4]; 
    SendBuffer[0]="EHLO " + mailserver + enter; 
    SendBuffer[1]="AUTH LOGIN" + enter; 
    SendBuffer[2]=Base64Encode(username) + enter; 
    SendBuffer[3]=Base64Encode(password) + enter; 
if(!Dialog(SendBuffer,"SMTP服务器验证失败,请核对用户名和密码。")) 
     return false; 
   } 
   else 
   { 
    SendBufferstr="HELO " + mailserver + enter; 
    if(!Dialog(SendBufferstr,"")) 
     return false; 
   } 
   SendBufferstr="MAIL FROM:<" + From + ">" + enter; 
   if(!Dialog(SendBufferstr,"发件人地址错误,或不能为空")) 
    return false; 
   //把传过来的收件人的地址分割然后提交给服务器
   string split=";";
   string []address=Regex.Split (Recipient,split);
   SendBuffer=new string [address.Length];
   for(int i=0;i<SendBuffer.Length;i++)
   {
    SendBuffer[i]="RCPT TO:<" +address[i]+">" + enter;
   }
   if(!Dialog(SendBuffer,"收件人地址有误")) 
    return false; 
   SendBufferstr="DATA" + enter; 
   if(!Dialog(SendBufferstr,"")) 
    return false; 
   SendBufferstr="From:" + FromName + "<" + From +">" +enter;
SendBufferstr += enter + "." + enter; 
   if(!Dialog(SendBufferstr,"错误信件信息")) 
    return false; 
   SendBufferstr="QUIT" + enter; 
   if(!Dialog(SendBufferstr,"断开连接时错误")) 
    return false; 
   //关闭流对象
   ns.Close(); 
   //关闭连接
   tc.Close();
   FilePath=null;
   return true; 
  }
以上即为发送不带附件的邮件SMTP命令用代码实现的过程。
5.2  AddExtra类
这个附加的小类只是提供一些返回当前系统时间,获取主机名,主机IP,有关帮助等小的功能,在此仅对帮助信息中的“关于”操作函数稍加说明。因为它说明了在C Sharp 
 << 上一页  [11] [12] [13] [14] [15] [16] [17] [18] 下一页 
C#电子邮件客户端软件设计(开题报告+英文文献+答辩PPT) 第16页下载如图片无法显示或论文不完整,请联系qq752018766