C#实现SMTP服务器,使用TCP命令实现,功能比较完善[6]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 qs1976 的 blog

    ((mailmessage.subject==string.empty || mailmessage.subject==null)?"subject:":((mailmessage.charset=="")?("subject:" +
    mailmessage.subject):("subject:" + "=?" + mailmessage.charset.toupper() + "?b?" +
    base64encode(mailmessage.subject) +"?="))) + crlf;
   sendbufferstr+="x-priority:" + priority + crlf;
   sendbufferstr+="x-msmail-priority:" + priority + crlf;
   sendbufferstr+="importance:" + priority + crlf;
   sendbufferstr+="x-mailer: lion.web.mail.smtpmail pubclass [cn]" + crlf;
   sendbufferstr+="mime-version: 1.0" + crlf;
   if(mailmessage.attachments.count!=0)
   {
    sendbufferstr+="content-type: multipart/mixed;" + crlf;
    sendbufferstr += " boundary=\"====="+
     (html?"001_dragon520636771063_":"001_dragon303406132050_")+"=====\""+crlf+crlf;
   }

   if(html)
   {
    if(mailmessage.attachments.count==0)
    {
     sendbufferstr += "content-type: multipart/alternative;"+crlf;//内容格式和分隔符
     sendbufferstr += " boundary=\"=====003_dragon520636771063_=====\""+crlf+crlf;
     sendbufferstr += "this is a multi-part message in mime format."+crlf+crlf;
    }
    else
    {
     sendbufferstr +="this is a multi-part message in mime format."+crlf+crlf;
     sendbufferstr += "--=====001_dragon520636771063_====="+crlf;
     sendbufferstr += "content-type: multipart/alternative;"+crlf;//内容格式和分隔符
     sendbufferstr += " boundary=\"=====003_dragon520636771063_=====\""+crlf+crlf;
    }
    sendbufferstr += "--=====003_dragon520636771063_====="+crlf;
    sendbufferstr += "content-type: text/plain;"+ crlf;
    sendbufferstr += ((mailmessage.charset=="")?(" charset=\"iso-8859-1\""):(" charset=\"" +

     mailmessage.charset.tolower() + "\"")) + crlf;
    sendbufferstr+="content-transfer-encoding: base64" + crlf + crlf;
    sendbufferstr+= base64encode("邮件内容为html格式,请选择html方式查看") + crlf + crlf;

    sendbufferstr += "--=====003_dragon520636771063_====="+crlf;


    sendbufferstr+="content-type: text/html;" + crlf;
    sendbufferstr+=((mailmessage.charset=="")?(" charset=\"iso-8859-1\""):(" charset=\"" +
     mailmessage.charset.tolower() + "\"")) + crlf;
    sendbufferstr+="content-transfer-encoding: base64" + crlf + crlf;
    sendbufferstr+= base64encode(mailmessage.body) + crlf + crlf;
    sendbufferstr += "--=====003_dragon520636771063_=====--"+crlf;
   }
   else
   {
    if(mailmessage.attachments.count!=0)
    {
     sendbufferstr += "--=====001_dragon303406132050_====="+crlf;
    }
    sendbufferstr+="content-type: text/plain;" + crlf;
    sendbufferstr+=((mailmessage.charset=="")?(" charset=\"iso-8859-1\""):(" charset=\"" +
     mailmessage.charset.tolower() + "\"")) + crlf;
    sendbufferstr+="content-transfer-encoding: base64" + crlf + crlf;
    sendbufferstr+= base64encode(mailmessage.body) + crlf;
   }
 
   //sendbufferstr += "content-transfer-encoding: base64"+crlf;

    if(mailmessage.attachments.count!=0)
   {
    for(int i=0;i<mailmessage.attachments.count;i++)
    {
     string filepath = (string)mailmessage.attachments[i];
     sendbufferstr += "--====="+
      (html?"001_dragon520636771063_":"001_dragon303406132050_") +"====="+crlf;
     //sendbufferstr += "content-type: application/octet-stream"+crlf;
     sendbufferstr += "content-type: text/plain;"+crlf;
     sendbufferstr += " name=\"=?"+mailmessage.charset.toupper()+"?b?"+

本文关键:C#实现SMTP服务器,使用TCP命令实现,功能比较完善
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top