在為公司寫通知服務(wù)時(shí),從網(wǎng)上找到了以上地址,非常感謝原作者創(chuàng)造性的勞動(dòng)。改寫的目的是為了適應(yīng)作為服務(wù)運(yùn)行的要求:
1、適應(yīng)多線程的要求,發(fā)送郵件服務(wù)可在后臺(tái)運(yùn)行,將與smtp服務(wù)器的連接視為獨(dú)占資源。
2、適應(yīng)穩(wěn)定性的要求,不再以簡(jiǎn)單地拋出異常來處理錯(cuò)誤,在出現(xiàn)異常后等待一定時(shí)間間隔后重試,重試一段時(shí)間間隔后若還時(shí)發(fā)不出去,則認(rèn)為是smtp出錯(cuò),返回發(fā)送郵件不成功的標(biāo)識(shí)。
3、精簡(jiǎn)屬性、方法,與郵件相關(guān)的信息不再作為屬性,而是作為send的參數(shù)傳入;只公布了一個(gè)無(wú)重載的send方法。以此類為基類,另寫通知服務(wù)要求的接口方法。
以下是改寫后的代碼:
using system;
using system.text;
using system.io;
using system.net;
using system.net.sockets;
using system.collections;
using system.threading;
namespace deep.sendemail
{
 #region aspnetpager server control
 /// <summary>
 /// 郵件可以通過 microsoft windows 2000 中內(nèi)置的 smtp 郵件服務(wù)或任意 smtp 服務(wù)器來傳送
 /// </summary>
 public class smtpmail
 {
 private const string enter="/r/n";
 /// <summary>
 /// 設(shè)定語(yǔ)言代碼,默認(rèn)設(shè)定為gb2312,如不需要可設(shè)置為""
 /// </summary>
 private string m_charset="gb2312";
 
 /// <summary>
 /// 服務(wù)器交互記錄
 /// </summary>
 private stringbuilder m_logs = new stringbuilder();
 private string m_errcode;
 /// <summary>
 /// smtp錯(cuò)誤代碼哈希表
 /// </summary>
 private hashtable m_errcodeht = new hashtable();
 /// <summary>
 /// smtp正確代碼哈希表
 /// </summary>
 private hashtable m_rightcodeht = new hashtable();
 
 /// <summary>
 /// 最多收件人數(shù)量
 /// </summary>
 private int m_recipientmaxnum = 2;
 /// <summary>
 /// 重復(fù)時(shí)間,以秒為單位
 /// </summary>
 private int m_repeattime = 120;
 /// <summary>
 /// 服務(wù)器出錯(cuò)或拒絕后的等待時(shí)間,以毫秒為單位
 /// </summary>
 private int m_waittime = 20000;
 /// <summary>
 /// 初始化 <see cref="lion.web.mail.smtpmail"/> 類的新實(shí)例
 /// </summary>
 public smtpmail()
 {
 smtpcodeadd();
 }
 #region properties 定義屬性
 /// <summary>
 /// 服務(wù)器交互記錄,如發(fā)現(xiàn)本組件不能使用的smtp服務(wù)器,請(qǐng)將出錯(cuò)時(shí)的logs發(fā)給我([email protected]),我將盡快查明原因。
 /// </summary>
 public string logs
 {
 get
 {
 return m_logs.tostring();
 }
 }
 /// <summary>
 /// 最多收件人數(shù)量
 /// </summary>
 public int recipientmaxnum
 {
 set
 {
 m_recipientmaxnum = value;
 }
 get
 {
 return m_recipientmaxnum;
 }
 }
 /// <summary>
 /// 設(shè)定語(yǔ)言代碼,默認(rèn)設(shè)定為gb2312,如不需要可設(shè)置為""
 /// </summary>
 public string charset
 {
 get
 {
 return this.m_charset;
 }
 set
 {
 this.m_charset = value;
 }
 }
 
 /// <summary>
 /// 重復(fù)時(shí)間,以秒為單位
 /// </summary>
 public int repeattime
 {
 get {return m_repeattime;}
 set {m_repeattime = value;}
 }
 /// <summary>
 /// 服務(wù)器出錯(cuò)或拒絕后的等待時(shí)間,以毫秒為單位
 /// </summary>
 public int waittime
 {
 get {return m_waittime;}
 set {m_waittime = value > 10000?value:10000;}
 }
 #endregion
 #region methods 定義方法
 /// <summary>
 /// 郵件服務(wù)器域名和驗(yàn)證信息
 /// 形如:"user:[email protected]:25",也可省略次要信息。如"user:[email protected]"或"www.server.com"
 /// </summary>
 /// <param name="maildomain">輸入用戶名、密碼、郵件服務(wù)器域名、端口號(hào)</param>
 /// <param name="mailserver">返回郵件服務(wù)器域名</param>
 /// <param name="mailserverusername">返回用戶名</param>
 /// <param name="password">返回密碼</param>
 /// <param name="mailserverport">返回端口號(hào)</param>
 /// <param name="needsmtp">返回是否需要smtp驗(yàn)證</param>
 /// <returns></returns>
 private bool setmaildomain(string maildomain,out string mailserver,out string mailserverusername,out string password,
 out int mailserverport,out bool needsmtp)
 {
 bool isright = false;
 //為輸出變量賦初值
 mailserver = string.empty;
 mailserverusername = string.empty;
 password = string.empty;
 mailserverport = 25;
 needsmtp = false;
 mailserver = maildomain.trim();
 int tempint;
 if( mailserver != "" )
 {
 tempint = mailserver.indexof("@");
 isright = true;
 if(tempint!=-1)
 {
 string str = mailserver.substring(0,tempint);
 mailserverusername = str.substring(0,str.indexof(":"));
 password = str.substring(str.indexof(":")+1,str.length-str.indexof(":")-1);
 needsmtp = !(password==string.empty);
 mailserver = maildomain.substring(tempint+1,maildomain.length-tempint-1);
 }
 tempint = mailserver.indexof(":");
 if(tempint != -1)
 {
 mailserverport = system.convert.toint32(mailserver.substring(tempint+1,mailserver.length-tempint-1));
 mailserver = mailserver.substring(0,tempint);
 }
 }
 return isright;
 }
 /// <summary>
 /// 添加郵件附件
 /// </summary>
 /// <param name="filepath">附件絕對(duì)路徑</param>
 private ilist addattachment(params string[] filepath)
 {
 if(filepath == null || filepath.length == 0)
 {
 return null;
 }
 ilist m_attachments = new system.collections.arraylist();// 郵件附件列表
 for(int i=0;i<filepath.length;i++)
 {
 if(file.exists(filepath[i]))
 {
 m_attachments.add(filepath[i]);
 }
 else
 {
 m_logs.append("錯(cuò)誤:沒找到文件名為"+filepath[i]+"的附件文件!"+enter);
 }
 }
 return m_attachments;
 }
 
 /// <summary>
 /// 添加一組收件人(不超過m_recipientmaxnum個(gè)),參數(shù)為字符串?dāng)?shù)組
 /// </summary>
 /// <param name="recipients">保存有收件人地址的字符串?dāng)?shù)組(不超過m_recipientmaxnum個(gè))</param> 
 private hashtable addrecipient(params string[] recipients)
 {
 if(recipients==null || recipients.length == 0)
 {
 return null;
 }
 hashtable recipientlist=new hashtable();// 收件人列表
 for(int i=0;i<recipients.length;i++)
 {
 string recipient = recipients[i].trim();
 if(recipient !=string.empty && recipient.indexof("@") != -1)
 {
 recipientlist.add(recipientlist.count,recipients[i]);
 }
 }
 return recipientlist;
 }
 /// <summary>
 /// 發(fā)送郵件方法
 /// </summary>
 /// <param name="smtpserver">smtp服務(wù)器信息,如"username:[email protected]:25",也可去掉部分次要信息,如"www.smtpserver.com"</param>
 /// <param name="from">發(fā)件人mail地址</param>
 /// <param name="fromname">發(fā)件人姓名</param>
 /// <param name="to">收件人地址列表</param>
 /// <param name="toname">收件人姓名</param>
 /// <param name="html">是否html郵件</param>
 /// <param name="subject">郵件主題</param>
 /// <param name="body">郵件正文</param>
 /// <param name="filepath">郵件附件列表</param>
 public bool send(string smtpserver,string from,string fromname,string[] recipientadd,string recipientname,bool ishtml,string subject,priority priority, string body,string[] filepath)
 {
 //如果收件人多于服務(wù)器可同時(shí)發(fā)送的最大值,則分多次發(fā)送
 if(recipientadd.length > recipientmaxnum)
 {
 string[] recipientadd1 = new string[recipientmaxnum];
 string[] recipientadd2 = new string[recipientadd.length - recipientmaxnum];
 for(int i = 0;i < recipientadd.length; i++)
 {
 if(i < recipientmaxnum)
 {
 recipientadd1[i] = recipientadd[i];
 }
 else
 {
 recipientadd2[i - recipientmaxnum] = recipientadd[i];
 }
 }
 return send(smtpserver,from,fromname,recipientadd1,recipientname,ishtml,subject,priority, body,filepath)
 &&
 send(smtpserver,from,fromname,recipientadd2,recipientname,ishtml,subject,priority, body,filepath);
 }
 if(m_logs.length > 2048)
 {
 m_logs.remove(0,m_logs.length);
 }
 string mailserver="";// 郵件服務(wù)器域名
 int mailserverport=25;// 郵件服務(wù)器端口號(hào)
 string username="";// smtp認(rèn)證時(shí)使用的用戶名
 string password="";// smtp認(rèn)證時(shí)使用的密碼
 bool needsmtp=false;// 是否需要smtp驗(yàn)證
 setmaildomain(smtpserver,out mailserver,out username,out password,
 out mailserverport,out needsmtp);
 if(mailserver.trim()=="")
 {
 m_logs.append("必須指定smtp服務(wù)器"+enter);
 return false;
 }
 ilist attachments = addattachment(filepath);// 郵件附件列表
 hashtable recipients = addrecipient(recipientadd);// 收件人列表
 if(recipients == null || recipients.count == 0 )
 {
 m_logs.append("必須指定收件人"+enter);
 return false;
 }
 if(recipients.count > recipientmaxnum)
 {
 m_logs.append("一次發(fā)送的收件人太多"+enter);
 return false;
 }
 bool issuccessful = false;
 lock(this)
 {
 tcpclient tcpclientobject = null;// tcpclient對(duì)象,用于連接服務(wù)器
 networkstream networkstreamobject = null;// networkstream對(duì)象
 datetime datetimebegin = datetime.now;
 int usetime = 0;
 while(! ( usetime > repeattime || issuccessful))
 {
 try
 {
 tcpclientobject=new tcpclient(mailserver,mailserverport);
 networkstreamobject = tcpclientobject.getstream();
 issuccessful =sendemail(networkstreamobject,needsmtp,mailserver,username,password,recipients,from,
 fromname,recipientname,subject,priority.tostring(),attachments, ishtml, body);
 }
 catch(exception e)
 {
 m_logs.append("錯(cuò)誤:"+e.message+enter);
 }
 finally
 {
 if(networkstreamobject!=null)networkstreamobject.close();
 if(tcpclientobject!=null)tcpclientobject.close();
 if(!issuccessful)
 {
 string n = thread.currentthread.name;
 thread.sleep(waittime);
 }
 usetime = ((timespan)(datetime.now - datetimebegin)).seconds;
 }
 }
 }
 return issuccessful;
 }
 
 #endregion
 #region private helper functions
 /// <summary>
 /// smtp回應(yīng)代碼哈希表
 /// </summary>
 private void smtpcodeadd()
 {
 m_errcodeht.add("500","郵箱地址錯(cuò)誤");
 m_errcodeht.add("501","參數(shù)格式錯(cuò)誤");
 m_errcodeht.add("502","命令不可實(shí)現(xiàn)");
 m_errcodeht.add("503","服務(wù)器需要smtp驗(yàn)證");
 m_errcodeht.add("504","命令參數(shù)不可實(shí)現(xiàn)");
 m_errcodeht.add("421","服務(wù)未就緒,關(guān)閉傳輸信道");
 m_errcodeht.add("450","要求的郵件操作未完成,郵箱不可用(例如,郵箱忙)");
 m_errcodeht.add("550","要求的郵件操作未完成,郵箱不可用(例如,郵箱未找到,或不可訪問)");
 m_errcodeht.add("451","放棄要求的操作;處理過程中出錯(cuò)");
 m_errcodeht.add("551","用戶非本地,請(qǐng)嘗試<forward-path>");
 m_errcodeht.add("452","系統(tǒng)存儲(chǔ)不足,要求的操作未執(zhí)行");
 m_errcodeht.add("552","過量的存儲(chǔ)分配,要求的操作未執(zhí)行");
 m_errcodeht.add("553","郵箱名不可用,要求的操作未執(zhí)行(例如郵箱格式錯(cuò)誤)");
 m_errcodeht.add("432","需要一個(gè)密碼轉(zhuǎn)換");
 m_errcodeht.add("534","認(rèn)證機(jī)制過于簡(jiǎn)單");
 m_errcodeht.add("538","當(dāng)前請(qǐng)求的認(rèn)證機(jī)制需要加密");
 m_errcodeht.add("454","臨時(shí)認(rèn)證失敗");
 m_errcodeht.add("530","需要認(rèn)證");
 m_rightcodeht.add("220","服務(wù)就緒");
 m_rightcodeht.add("250","要求的郵件操作完成");
 m_rightcodeht.add("251","用戶非本地,將轉(zhuǎn)發(fā)向<forward-path>");
 m_rightcodeht.add("354","開始郵件輸入,以<enter>.<enter>結(jié)束");
 m_rightcodeht.add("221","服務(wù)關(guān)閉傳輸信道");
 m_rightcodeht.add("334","服務(wù)器響應(yīng)驗(yàn)證base64字符串");
 m_rightcodeht.add("235","驗(yàn)證成功");
 }
 /// <summary>
 /// 將字符串編碼為base64字符串
 /// </summary>
 /// <param name="str">要編碼的字符串</param>
 private string base64encode(string str)
 {
 byte[] barray;
 barray=encoding.default.getbytes(str);
 return convert.tobase64string(barray);
 }
 /// <summary>
 /// 將base64字符串解碼為普通字符串
 /// </summary>
 /// <param name="str">要解碼的字符串</param>
 private string base64decode(string str)
 {
 byte[] barray;
 barray=convert.frombase64string(str);
 return encoding.default.getstring(barray);
 }
 
 /// <summary>
 /// 得到上傳附件的文件流
 /// </summary>
 /// <param name="filepath">附件的絕對(duì)路徑</param>
 private string getstream(string filepath)
 {
 byte[] by = null;
 system.io.filestream filestr = null;
 string streamstring = "";
 try
 {
 //建立文件流對(duì)象
 filestr=new system.io.filestream(filepath,system.io.filemode.open);
 by=new byte[system.convert.toint32(filestr.length)];
 filestr.read(by,0,by.length);
 streamstring = system.convert.tobase64string(by);
 }
 catch(exception ex)
 {
 //寫錯(cuò)誤日志
 m_logs.append("錯(cuò)誤:"+ex.message+enter);
 }
 finally
 {
 if(filestr != null)
 {
 filestr.close();
 }
 }
 return streamstring;
 }
 /// <summary>
 /// 發(fā)送smtp命令
 /// </summary> 
 private bool sendcommand(string str,networkstream _networkstreamobject)
 {
 byte[] writebuffer;
 if(str==null||str.trim()==string.empty)
 {
 return true;
 }
 m_logs.append(str+enter);
 writebuffer = encoding.default.getbytes(str);
 try
 {
 _networkstreamobject.write(writebuffer,0,writebuffer.length);
 }
 catch(exception ex)
 {
 //寫日志
 m_logs.append("錯(cuò)誤:"+ex.message+enter);
 return false;
 }
 return true;
 }
 /// <summary>
 /// 接收smtp服務(wù)器回應(yīng)
 /// </summary>
 private string recvresponse(networkstream _networkstreamobject)
 {
 int streamsize = 0;
 string returnvalue = string.empty;
 byte[] readbuffer = new byte[1024] ;
 try
 {
 streamsize = _networkstreamobject.read(readbuffer,0,readbuffer.length);
 }
 catch(exception ex)
 {
 //寫日志
 m_logs.append("錯(cuò)誤:"+ex.message+enter);
 m_errcode = ex.message;
 return "false";
 }
 if (streamsize==0)
 {
 return returnvalue ;
 }
 else
 {
 returnvalue = encoding.default.getstring(readbuffer).substring(0,streamsize);
 m_logs.append(returnvalue+enter);
 return returnvalue;
 }
 }
 /// <summary>
 /// 與服務(wù)器交互,發(fā)送一條命令并接收回應(yīng)。
 /// </summary>
 /// <param name="str">一個(gè)要發(fā)送的命令</param>
 private bool dialog(string str,networkstream _networkstream)
 {
 if(str==null||str.trim()=="")
 {
 return true;
 }
 if(sendcommand(str,_networkstream))
 {
 string rr=recvresponse(_networkstream);
 if(rr=="false")
 {
 return false;
 }
 string rrcode=rr.substring(0,3);
 if(m_rightcodeht[rrcode]!=null)
 {
 return true;
 }
 else
 {
 m_errcode = rrcode;
 return false;
 }
 }
 else
 {
 return false;
 }
 }
 /// <summary>
 /// 與服務(wù)器交互,發(fā)送一組命令并接收回應(yīng)。
 /// </summary>
 private bool dialog(string[] str,networkstream _networkstream)
 {
 for(int i=0;i<str.length;i++)
 {
 if(!dialog(str[i],_networkstream))
 {
 return false;
 }
 }
 return true;
 }
 
 /// <summary>
 /// sendemail
 /// </summary>
 /// <returns></returns>
 private bool sendemail(networkstream _networkstream,bool needsmtp,string mailserver,string username,string password,hashtable recipients,string from,
 string fromname,string recipientname,string subject,string priority,ilist attachments,bool ishtml,
 string body)
 {
 //驗(yàn)證網(wǎng)絡(luò)連接是否正確
 if(m_rightcodeht[recvresponse(_networkstream).substring(0,3)]==null)
 {
 return false;
 }
 string[] sendbuffer;
 string sendbufferstr;
 stringbuilder sendbufferstrbuilder = new stringbuilder();
 //進(jìn)行smtp驗(yàn)證
 if(needsmtp)
 {
 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,_networkstream))
 {
 return false;
 }
 }
 else
 {
 sendbufferstr="helo " + mailserver + enter;
 if(!dialog(sendbufferstr,_networkstream))
 return false;
 }
 //
 sendbufferstr="mail from:<" + from + ">" + enter;
 if(!dialog(sendbufferstr,_networkstream))
 return false;
 //
 sendbuffer=new string[m_recipientmaxnum];
 for(int i=0;i<recipients.count;i++)
 {
 sendbuffer[i]="rcpt to:<" + recipients[i].tostring() +">" + enter;
 }
 if(!dialog(sendbuffer,_networkstream))
 return false;
 sendbufferstr="data" + enter;
 if(!dialog(sendbufferstr,_networkstream))
 return false;
 sendbufferstrbuilder.append("from:" + fromname + "<" + from +">" +enter);
 
 sendbufferstrbuilder.append("to:=?"+charset.toupper()+"?b?"+base64encode(recipientname)+"?="+"<"+recipients[0]+">"+enter);
 
 sendbufferstrbuilder.append("cc:");
 for(int i=0;i<recipients.count;i++)
 {
 sendbufferstrbuilder.append(recipients[i].tostring() + "<" + recipients[i].tostring() +">,");
 }
 sendbufferstrbuilder.append(enter);
 sendbufferstrbuilder.append(((subject==string.empty || subject==null)?"subject:":((charset=="")?("subject:" + subject):("subject:" + "=?" + charset.toupper() + "?b?" + base64encode(subject) +"?="))) + enter);
 sendbufferstrbuilder.append("x-priority:" + priority + enter);
 sendbufferstrbuilder.append("x-msmail-priority:" + priority + enter);
 sendbufferstrbuilder.append("importance:" + priority + enter);
 sendbufferstrbuilder.append("x-mailer: lion.web.mail.smtpmail pubclass [cn]" + enter);
 sendbufferstrbuilder.append("mime-version: 1.0" + enter);
 if(attachments != null && attachments.count!=0)
 {
 sendbufferstrbuilder.append("content-type: multipart/mixed;" + enter);
 sendbufferstrbuilder.append(" boundary=/"====="+(ishtml?"001_dragon520636771063_":"001_dragon303406132050_")+"=====/""+enter+enter);
 }
 if(ishtml)
 {
 if(attachments != null && attachments.count==0)
 {
 sendbufferstrbuilder.append("content-type: multipart/alternative;"+enter);//內(nèi)容格式和分隔符
 sendbufferstrbuilder.append(" boundary=/"=====003_dragon520636771063_=====/""+enter+enter);
 sendbufferstrbuilder.append("this is a multi-part message in mime format."+enter+enter);
 }
 else
 {
 sendbufferstrbuilder.append("this is a multi-part message in mime format."+enter+enter);
 sendbufferstrbuilder.append("--=====001_dragon520636771063_====="+enter);
 sendbufferstrbuilder.append("content-type: multipart/alternative;"+enter);//內(nèi)容格式和分隔符
 sendbufferstrbuilder.append(" boundary=/"=====003_dragon520636771063_=====/""+enter+enter); 
 }
 sendbufferstrbuilder.append("--=====003_dragon520636771063_====="+enter);
 sendbufferstrbuilder.append("content-type: text/plain;"+ enter);
 sendbufferstrbuilder.append(((charset=="")?(" charset=/"iso-8859-1/""):(" charset=/"" + charset.tolower() + "/"")) + enter);
 sendbufferstrbuilder.append("content-transfer-encoding: base64" + enter + enter);
 sendbufferstrbuilder.append(base64encode("郵件內(nèi)容為html格式,請(qǐng)選擇html方式查看") + enter + enter);
 sendbufferstrbuilder.append("--=====003_dragon520636771063_====="+enter);
 
 sendbufferstrbuilder.append("content-type: text/html;" + enter);
 sendbufferstrbuilder.append(((charset=="")?(" charset=/"iso-8859-1/""):(" charset=/"" + charset.tolower() + "/"")) + enter);
 sendbufferstrbuilder.append("content-transfer-encoding: base64" + enter + enter);
 sendbufferstrbuilder.append(base64encode(body) + enter + enter);
 sendbufferstrbuilder.append("--=====003_dragon520636771063_=====--"+enter);
 }
 else
 {
 if(attachments != null && attachments.count!=0)
 {
 sendbufferstrbuilder.append("--=====001_dragon303406132050_====="+enter);
 }
 sendbufferstrbuilder.append("content-type: text/plain;" + enter);
 sendbufferstrbuilder.append(((charset=="")?(" charset=/"iso-8859-1/""):(" charset=/"" + charset.tolower() + "/"")) + enter);
 sendbufferstrbuilder.append("content-transfer-encoding: base64" + enter + enter);
 sendbufferstrbuilder.append(base64encode(body) + enter);
 }
 
 //sendbufferstr += "content-transfer-encoding: base64"+enter;
 if(attachments != null && attachments.count!=0)
 {
 for(int i=0;i<attachments.count;i++)
 {
 string filepath = (string)attachments[i];
 sendbufferstrbuilder.append("--====="+ (ishtml?"001_dragon520636771063_":"001_dragon303406132050_") +"====="+enter);
 //sendbufferstr += "content-type: application/octet-stream"+enter;
 sendbufferstrbuilder.append("content-type: text/plain;"+enter);
 sendbufferstrbuilder.append(" name=/"=?"+charset.toupper()+"?b?"+base64encode(filepath.substring(filepath.lastindexof("//")+1))+"?=/""+enter);
 sendbufferstrbuilder.append("content-transfer-encoding: base64"+enter);
 sendbufferstrbuilder.append("content-disposition: attachment;"+enter);
 sendbufferstrbuilder.append(" filename=/"=?"+charset.toupper()+"?b?"+base64encode(filepath.substring(filepath.lastindexof("//")+1))+"?=/""+enter+enter);
 sendbufferstrbuilder.append(getstream(filepath)+enter+enter);
 }
 sendbufferstrbuilder.append("--====="+ (ishtml?"001_dragon520636771063_":"001_dragon303406132050_") +"=====--"+enter+enter);
 }
 sendbufferstrbuilder.append(enter + "." + enter);
 sendbufferstr = sendbufferstrbuilder.tostring();
 if(!dialog(sendbufferstr,_networkstream))
 return false;
 sendbufferstr="quit" + enter;
 if(!dialog(sendbufferstr,_networkstream))
 return false;
 return true;
 }
 #endregion
 #region
 /*
 /// <summary>
 /// 添加一個(gè)密件收件人
 /// </summary>
 /// <param name="str">收件人地址</param>
 public bool addrecipientbcc(string str)
 {
 if(str==null||str.trim()=="")
 return true;
 if(recipientbccnum<10)
 {
 recipientbcc.add(recipientbccnum,str);
 recipientbccnum++;
 return true;
 }
 else
 {
 m_logs.append("錯(cuò)誤:收件人過多");
 return false;
 }
 }
 /// <summary>
 /// 添加一組密件收件人(不超過10個(gè)),參數(shù)為字符串?dāng)?shù)組
 /// </summary> 
 /// <param name="str">保存有收件人地址的字符串?dāng)?shù)組(不超過10個(gè))</param>
 public bool addrecipientbcc(string[] str)
 {
 for(int i=0;i<str.length;i++)
 {
 if(!addrecipientbcc(str[i]))
 {
 return false;
 }
 }
 return true;
 }
 */ 
 #endregion 
 }
 /// <summary>
 /// 郵件發(fā)送優(yōu)先級(jí)
 /// </summary>
 public enum priority
 {
 high,
 normal,
 low
 }
 #endregion
}