当思考成为习惯,成功将随之而至

做人要上进,厚道

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  55 随笔 :: 12 文章 :: 11 评论 :: 2 引用

最新评论

re: 一篇让人流泪的爱情故事(转) 张瑶 2008-04-08 00:18  
爱一个人不一定要拥有他,但是拥有一个人的时候一定要好好去爱他!


我自己有一段故事!具体是什么我就不说了!但是我没有好好珍惜!所以我后悔了 !


人就是这样! 当你失去的时候才知道珍惜!
re: 爱,到底是种什么样的感觉 WhyCome[at]live.cn 2008-03-17 07:53  
据说 这事经验很重要的说
re: 爱,到底是种什么样的感觉 武洁 2008-03-12 18:29  
你写得真的很棒。。。。。。。。。。。。。
不错不错,以前03的时候也做过!!
高手,小弟是刚刚学习C#的
如果你不介意我的知识寡陋
想和你交个朋友

QQ:492279855
re: 一篇让人流泪的爱情故事(转) 阳子 2006-04-11 21:07  
很感人的爱情故事!你的选择验证了“爱情有时意味着彼此牺牲”。我想那个女孩会因为生命中有你这样一个人而感到幸运的,又是结果并不是很重要,体验过程的美好才是刻骨铭心的。所以,A Za !用心去创造你的未来!还有,衷心祝福十年后你和那个女孩的生命轨迹产生新的交点!
re: EMAIL发送系统(C#+基于SMTP认证) blog of mb459 2005-12-10 23:07  
EMAIL发送系统(C#+基于SMTP认证) 2.0

这个是对于

[原创]EMAIL发送系统(C#+基于SMTP认证)
http://www.lionsky.net/MyWebsite/article/list.aspx?id=430
(见本贴回复)

的改版

前段时间有网友反馈了一些问题,这次主要做了一些修正

1,text模式下发往163的邮件内容不见了
2,如果用outlook接收而不是在网上看邮件的话,会发现正文内容,但其后跟着一些乱码.
3,一些新开通的邮箱收到的是乱码,如*@126.com

感谢 Lion互动网络论坛 的smhy8187和邮箱是grassdragon_china@yahoo.com.cn的朋友

欢迎大家提出修改建议,[注:发布时请保留版权]最好能把修改稿Mail给我一份,我们共同学习
我的Email:lion-a@sohu.com lion.net@163.com


------------------------------------------

以下是程序源码:



using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Collections;

namespace Lion.Web.Mail
{
/*
Create By lion
2004-04-23 19:00
Copyright (C) 2001,2002 www.LionSky.Net. All rights reserved.
Web: http://www.Lionsky.net ;;
Email: lion-a@sohu.com
Support .Net Framework Beta 2
*/
#region AspNetPager Server Control

/// <summary>
/// 邮件可以通过 Microsoft Windows 2000 中内置的 SMTP 邮件服务或任意 SMTP 服务器来传送
/// </summary>
public class SmtpMail
{

private string enter="\r\n";

/// <summary>
/// 设定语言代码,默认设定为GB2312,如不需要可设置为""
/// </summary>
private string _charset="GB2312";

/// <summary>
/// 发件人地址
/// </summary>
private string _from="";

/// <summary>
/// 发件人姓名
/// </summary>
private string _fromName="";

/// <summary>
/// 回复邮件地址
/// </summary>
///public string ReplyTo="";

/// <summary>
/// 收件人姓名
/// </summary>
private string _recipientName="";

/// <summary>
/// 收件人列表
/// </summary>
private Hashtable Recipient=new Hashtable();

/// <summary>
/// 邮件服务器域名
/// </summary>
private string mailserver="";

/// <summary>
/// 邮件服务器端口号
/// </summary>
private int mailserverport=25;

/// <summary>
/// SMTP认证时使用的用户名
/// </summary>
private string username="";

/// <summary>
/// SMTP认证时使用的密码
/// </summary>
private string password="";

/// <summary>
/// 是否需要SMTP验证
/// </summary>
private bool ESmtp=false;

/// <summary>
/// 是否Html邮件
/// </summary>
private bool _html=false;


/// <summary>
/// 邮件附件列表
/// </summary>
private IList Attachments;

/// <summary>
/// 邮件发送优先级,可设置为"High","Normal","Low"或"1","3","5"
/// </summary>
private string priority="Normal";

/// <summary>
/// 邮件主题
/// </summary>
private string _subject;

/// <summary>
/// 邮件正文
/// </summary>
private string _body;

/// <summary>
/// 密送收件人列表
/// </summary>
///private Hashtable RecipientBCC=new Hashtable();

/// <summary>
/// 收件人数量
/// </summary>
private int RecipientNum=0;

/// <summary>
/// 最多收件人数量
/// </summary>
private int recipientmaxnum=5;

/// <summary>
/// 密件收件人数量
/// </summary>
///private int RecipientBCCNum=0;

/// <summary>
/// 错误消息反馈
/// </summary>
private string errmsg;

/// <summary>
/// TcpClient对象,用于连接服务器
/// </summary>
private TcpClient tc;

/// <summary>
/// NetworkStream对象
/// </summary>
private NetworkStream ns;

/// <summary>
/// 服务器交互记录
/// </summary>
private string logs="";

/// <summary>
/// SMTP错误代码哈希表
/// </summary>
private Hashtable ErrCodeHT = new Hashtable();

/// <summary>
/// SMTP正确代码哈希表
/// </summary>
private Hashtable RightCodeHT = new Hashtable();


/// <summary>
/// 初始化 <see cref="Lion.Web.Mail.SmtpMail"/> 类的新实例
/// </summary>
public SmtpMail()
{
Attachments = new System.Collections.ArrayList();
}

#region Properties


/// <summary>
/// 邮件主题
/// </summary>
public string Subject
{
get
{
return this._subject;
}
set
{
this._subject = value;
}
}

/// <summary>
/// 邮件正文
/// </summary>
public string Body
{
get
{
return this._body;
}
set
{
this._body = value;
}
}


/// <summary>
/// 发件人地址
/// </summary>
public string From
{
get
{
return _from;
}
set
{
this._from = value;
}
}

/// <summary>
/// 设定语言代码,默认设定为GB2312,如不需要可设置为""
/// </summary>
public string Charset
{
get
{
return this._charset;
}
set
{
this._charset = value;
}
}

/// <summary>
/// 发件人姓名
/// </summary>
public string FromName
{
get
{
return this._fromName;
}
set
{
this._fromName = value;
}
}

/// <summary>
/// 收件人姓名
/// </summary>
public string RecipientName
{
get
{
return this._recipientName;
}
set
{
this._recipientName = value;
}
}

/// <summary>
/// 邮件服务器域名和验证信息
/// 形如:"user:pass@www.server.com:25",也可省略次要信息。如"user:pass@www.server.com"或"www.server.com"
/// </summary>
public string MailDomain
{
set
{
string maidomain=value.Trim();
int tempint;

if(maidomain!="")
{
tempint=maidomain.IndexOf("@");
if(tempint!=-1)
{
string str=maidomain.Substring(0,tempint);
MailServerUserName=str.Substring(0,str.IndexOf(":"));
MailServerPassWord=str.Substring(str.IndexOf(":")+1,str.Length-str.IndexOf

(":")-1);
maidomain=maidomain.Substring(tempint+1,maidomain.Length-tempint-1);
}

tempint=maidomain.IndexOf(":");
if(tempint!=-1)
{
mailserver=maidomain.Substring(0,tempint);
mailserverport=System.Convert.ToInt32(maidomain.Substring

(tempint+1,maidomain.Length-tempint-1));
}
else
{
mailserver=maidomain;

}


}

}
}



/// <summary>
/// 邮件服务器端口号
/// </summary>
public int MailDomainPort
{
set
{
mailserverport=value;
}
}



/// <summary>
/// SMTP认证时使用的用户名
/// </summary>
public string MailServerUserName
{
set
{
if(value.Trim()!="")
{
username=value.Trim();
ESmtp=true;
}
else
{
username="";
ESmtp=false;
}
}
}

/// <summary>
/// SMTP认证时使用的密码
/// </summary>
public string MailServerPassWord
{
set
{
password=value;
}
}

/// <summary>
/// 邮件发送优先级,可设置为"High","Normal","Low"或"1","3","5"
/// </summary>
public string Priority
{
set
{
switch(value.ToLower())
{
case "high":
priority="High";
break;

case "1":
priority="High";
break;

case "normal":
priority="Normal";
break;

case "3":
priority="Normal";
break;

case "low":
priority="Low";
break;

case "5":
priority="Low";
break;

default:
priority="Normal";
break;
}
}
}

/// <summary>
/// 是否Html邮件
/// </summary>
public bool Html
{
get
{
return this._html;
}
set
{
this._html = value;
}
}


/// <summary>
/// 错误消息反馈
/// </summary>
public string ErrorMessage
{
get
{
return errmsg;
}
}

/// <summary>
/// 服务器交互记录,如发现本组件不能使用的SMTP服务器,请将出错时的Logs发给我(lion-a@sohu.com),我将尽快查明

原因。
/// </summary>
public string Logs
{
get
{
return logs;
}
}

/// <summary>
/// 最多收件人数量
/// </summary>
public int RecipientMaxNum
{
set
{
recipientmaxnum = value;
}
}


#endregion

#region Methods


/// <summary>
/// 添加邮件附件
/// </summary>
/// <param name="FilePath">附件绝对路径</param>
public void AddAttachment(params string[] FilePath)
{
if(FilePath==null)
{
throw(new ArgumentNullException("FilePath"));
}
for(int i=0;i<FilePath.Length;i++)
{
Attachments.Add(FilePath);
}
}

/// <summary>
/// 添加一组收件人(不超过recipientmaxnum个),参数为字符串数组
/// </summary>
/// <param name="Recipients">保存有收件人地址的字符串数组(不超过recipientmaxnum个)</param>
public bool AddRecipient(params string[] Recipients)
{
if(Recipient==null)
{
Dispose();
throw(new ArgumentNullException("Recipients"));
}
for(int i=0;i<Recipients.Length;i++)
{
string recipient = Recipients.Trim();
if(recipient==String.Empty)
{
Dispose();
throw(new ArgumentNullException("Recipients["+ i +"]"));
}
if(recipient.IndexOf("@")==-1)
{
Dispose();
throw(new ArgumentException("Recipients.IndexOf(\"@\")==-1","Recipients"));
}
if(!AddRecipient(recipient))
{
return false;
}
}
return true;
}

/// <summary>
/// 发送邮件方法,所有参数均通过属性设置。
/// </summary>
public bool Send()
{
if(mailserver.Trim()=="")
{
throw(new ArgumentNullException("Recipient","必须指定SMTP服务器"));
}

return SendEmail();

}


/// <summary>
/// 发送邮件方法
/// </summary>
/// <param name="smtpserver">smtp服务器信息,如"username:password@www.smtpserver.com:25",也可去掉部分次要信

息,如"www.smtpserver.com"</param>
public bool Send(string smtpserver)
{
MailDomain=smtpserver;
return Send();
}


/// <summary>
/// 发送邮件方法
/// </summary>
/// <param name="smtpserver">smtp服务器信息,如"username:password@www.smtpserver.com:25",也可去掉部分次要信

息,如"www.smtpserver.com"</param>
/// <param name="from">发件人mail地址</param>
/// <param name="fromname">发件人姓名</param>
/// <param name="to">收件人地址</param>
/// <param name="toname">收件人姓名</param>
/// <param name="html">是否HTML邮件</param>
/// <param name="subject">邮件主题</param>
/// <param name="body">邮件正文</param>
public bool Send(string smtpserver,string from,string fromname,string to,string toname,bool html,string

subject,string body)
{
MailDomain=smtpserver;
From=from;
FromName=fromname;
AddRecipient(to);
RecipientName=toname;
Html=html;
Subject=subject;
Body=body;
return Send();
}


#endregion

#region Private Helper Functions

/// <summary>
/// 添加一个收件人
/// </summary>
/// <param name="Recipients">收件人地址</param>
private bool AddRecipient(string Recipients)
{
if(RecipientNum<recipientmaxnum)
{
Recipient.Add(RecipientNum,Recipients);
RecipientNum++;
return true;
}
else
{
Dispose();
throw(new ArgumentOutOfRangeException("Recipients","收件人过多不可多于 "+ recipientmaxnum +"

个"));
}
}

void Dispose()
{
if(ns!=null)ns.Close();
if(tc!=null)tc.Close();
}

/// <summary>
/// SMTP回应代码哈希表
/// </summary>
private void SMTPCodeAdd()
{
ErrCodeHT.Add("500","邮箱地址错误");
ErrCodeHT.Add("501","参数格式错误");
ErrCodeHT.Add("502","命令不可实现");
ErrCodeHT.Add("503","服务器需要SMTP验证");
ErrCodeHT.Add("504","命令参数不可实现");
ErrCodeHT.Add("421","服务未就绪,关闭传输信道");
ErrCodeHT.Add("450","要求的邮件操作未完成,邮箱不可用(例如,邮箱忙)");
ErrCodeHT.Add("550","要求的邮件操作未完成,邮箱不可用(例如,邮箱未找到,或不可访问)");
ErrCodeHT.Add("451","放弃要求的操作;处理过程中出错");
ErrCodeHT.Add("551","用户非本地,请尝试<forward-path>");
ErrCodeHT.Add("452","系统存储不足,要求的操作未执行");
ErrCodeHT.Add("552","过量的存储分配,要求的操作未执行");
ErrCodeHT.Add("553","邮箱名不可用,要求的操作未执行(例如邮箱格式错误)");
ErrCodeHT.Add("432","需要一个密码转换");
ErrCodeHT.Add("534","认证机制过于简单");
ErrCodeHT.Add("538","当前请求的认证机制需要加密");
ErrCodeHT.Add("454","临时认证失败");
ErrCodeHT.Add("530","需要认证");

RightCodeHT.Add("220","服务就绪");
RightCodeHT.Add("250","要求的邮件操作完成");
RightCodeHT.Add("251","用户非本地,将转发向<forward-path>");
RightCodeHT.Add("354","开始邮件输入,以<enter>.<enter>结束");
RightCodeHT.Add("221","服务关闭传输信道");
RightCodeHT.Add("334","服务器响应验证Base64字符串");
RightCodeHT.Add("235","验证成功");
}


/// <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">附件的绝对路径</param>
private string GetStream(string FilePath)
{
//建立文件流对象
System.IO.FileStream FileStr=new System.IO.FileStream(FilePath,System.IO.FileMode.Open);
byte[] by=new byte[System.Convert.ToInt32(FileStr.Length)];
FileStr.Read(by,0,by.Length);
FileStr.Close();
return(System.Convert.ToBase64String(by));
}

/// <summary>
/// 发送SMTP命令
/// </summary>
private bool SendCommand(string str)
{
byte[] WriteBuffer;
if(str==null||str.Trim()==String.Empty)
{
return true;
}
logs+=str;
WriteBuffer = Encoding.Default.GetBytes(str);
try
{
ns.Write(WriteBuffer,0,WriteBuffer.Length);
}
catch
{
errmsg="网络连接错误";
return false;
}
return true;
}

/// <summary>
/// 接收SMTP服务器回应
/// </summary>
private string RecvResponse()
{
int StreamSize;
string ReturnValue = String.Empty;
byte[] ReadBuffer = new byte[1024] ;
try
{
StreamSize=ns.Read(ReadBuffer,0,ReadBuffer.Length);
}
catch
{
errmsg="网络连接错误";
return "false";
}

if (StreamSize==0)
{
return ReturnValue ;
}
else
{
ReturnValue = Encoding.Default.GetString(ReadBuffer).Substring(0,StreamSize);
logs+=ReturnValue+this.enter;
return ReturnValue;
}
}

/// <summary>
/// 与服务器交互,发送一条命令并接收回应。
/// </summary>
/// <param name="str">一个要发送的命令</param>
/// <param name="errstr">如果错误,要反馈的信息</param>
private bool Dialog(string str,string errstr)
{
if(str==null||str.Trim()=="")
{
return true;
}
if(SendCommand(str))
{
string RR=RecvResponse();
if(RR=="false")
{
return false;
}
string RRCode=RR.Substring(0,3);
if(RightCodeHT[RRCode]!=null)
{
return true;
}
else
{
if(ErrCodeHT[RRCode]!=null)
{
errmsg+=(RRCode+ErrCodeHT[RRCode].ToString());
errmsg+=enter;
}
else
{
errmsg+=RR;
}
errmsg+=errstr;
return false;
}
}
else
{
return false;
}

}


/// <summary>
/// 与服务器交互,发送一组命令并接收回应。
/// </summary>

private bool Dialog(string[] str,string errstr)
{
for(int i=0;i<str.Length;i++)
{
if(!Dialog(str,""))
{
errmsg+=enter;
errmsg+=errstr;
return false;
}
}

return true;
}

/// <summary>
/// SendEmail
/// </summary>
/// <returns></returns>
private bool SendEmail()
{
//连接网络
try
{
tc=new TcpClient(mailserver,mailserverport);
}
catch(Exception e)
{
errmsg=e.ToString();
return false;
}

ns = tc.GetStream();
SMTPCodeAdd();

//验证网络连接是否正确
if(RightCodeHT[RecvResponse().Substring(0,3)]==null)
{
errmsg="网络连接失败";
return false;
}


string[] SendBuffer;
string SendBufferstr;

//进行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;

//
SendBuffer=new string[recipientmaxnum];
for(int i=0;i<Recipient.Count;i++)
{
SendBuffer="RCPT TO:<" + Recipient.ToString() +">" + enter;

}
if(!Dialog(SendBuffer,"收件人地址有误"))
return false;

/*
SendBuffer=new string[10];
for(int i=0;i<RecipientBCC.Count;i++)
{

SendBuffer="RCPT TO:<" + RecipientBCC.ToString() +">" + enter;

}

if(!Dialog(SendBuffer,"密件收件人地址有误"))
return false;
*/
SendBufferstr="DATA" + enter;
if(!Dialog(SendBufferstr,""))
return false;

SendBufferstr="From:" + FromName + "<" + From +">" +enter;

//if(ReplyTo.Trim()!="")
//{
// SendBufferstr+="Reply-To: " + ReplyTo + enter;
//}

//SendBufferstr+="To:" + RecipientName + "<" + Recipient[0] +">" +enter;
SendBufferstr += "To:=?"+Charset.ToUpper()+"?B?"+Base64Encode(RecipientName)+"?="+"<"+Recipient[0]

+">"+enter;

SendBufferstr+="CC:";
for(int i=0;i<Recipient.Count;i++)
{
SendBufferstr+=Recipient.ToString() + "<" + Recipient.ToString() +">,";
}
SendBufferstr+=enter;

SendBufferstr+=((Subject==String.Empty || Subject==null)?"Subject:":((Charset=="")?("Subject:" +

Subject):("Subject:" + "=?" + Charset.ToUpper() + "?B?" + Base64Encode(Subject) +"?="))) + enter;
SendBufferstr+="X-Priority:" + priority + enter;
SendBufferstr+="X-MSMail-Priority:" + priority + enter;
SendBufferstr+="Importance:" + priority + enter;
SendBufferstr+="X-Mailer: Lion.Web.Mail.SmtpMail Pubclass [cn]" + enter;
SendBufferstr+="MIME-Version: 1.0" + enter;
if(Attachments.Count!=0)
{
SendBufferstr+="Content-Type: multipart/mixed;" + enter;
SendBufferstr += " boundary=\"====="+

(Html?"001_Dragon520636771063_":"001_Dragon303406132050_")+"=====\""+enter+enter;
}

if(Html)
{
if(Attachments.Count==0)
{
SendBufferstr += "Content-Type: multipart/alternative;"+enter;//内容格式和分隔符
SendBufferstr += " boundary=\"=====003_Dragon520636771063_=====\""+enter+enter;

SendBufferstr += "This is a multi-part message in MIME format."+enter+enter;
}
else
{
SendBufferstr +="This is a multi-part message in MIME format."+enter+enter;
SendBufferstr += "--=====001_Dragon520636771063_====="+enter;
SendBufferstr += "Content-Type: multipart/alternative;"+enter;//内容格式和分隔符
SendBufferstr += " boundary=\"=====003_Dragon520636771063_=====\""+enter+enter;


}
SendBufferstr += "--=====003_Dragon520636771063_====="+enter;
SendBufferstr += "Content-Type: text/plain;"+ enter;
SendBufferstr += ((Charset=="")?(" charset=\"iso-8859-1\""):(" charset=\"" +

Charset.ToLower() + "\"")) + enter;
SendBufferstr+="Content-Transfer-Encoding: base64" + enter + enter;
SendBufferstr+= Base64Encode("邮件内容为HTML格式,请选择HTML方式查看") + enter + enter;

SendBufferstr += "--=====003_Dragon520636771063_====="+enter;



SendBufferstr+="Content-Type: text/html;" + enter;
SendBufferstr+=((Charset=="")?(" charset=\"iso-8859-1\""):(" charset=\"" +

Charset.ToLower() + "\"")) + enter;
SendBufferstr+="Content-Transfer-Encoding: base64" + enter + enter;
SendBufferstr+= Base64Encode(Body) + enter + enter;
SendBufferstr += "--=====003_Dragon520636771063_=====--"+enter;
}
else
{
if(Attachments.Count!=0)
{
SendBufferstr += "--=====001_Dragon303406132050_====="+enter;
}
SendBufferstr+="Content-Type: text/plain;" + enter;
SendBufferstr+=((Charset=="")?(" charset=\"iso-8859-1\""):(" charset=\"" +

Charset.ToLower() + "\"")) + enter;
SendBufferstr+="Content-Transfer-Encoding: base64" + enter + enter;
SendBufferstr+= Base64Encode(Body) + enter;
}

//SendBufferstr += "Content-Transfer-Encoding: base64"+enter;




if(Attachments.Count!=0)
{
for(int i=0;i<Attachments.Count;i++)
{
string filepath = (string)Attachments;
SendBufferstr += "--====="+

(Html?"001_Dragon520636771063_":"001_Dragon303406132050_") +"====="+enter;
//SendBufferstr += "Content-Type: application/octet-stream"+enter;
SendBufferstr += "Content-Type: text/plain;"+enter;
SendBufferstr += " name=\"=?"+Charset.ToUpper()+"?B?"+Base64Encode

(filepath.Substring(filepath.LastIndexOf("\\")+1))+"?=\""+enter;
SendBufferstr += "Content-Transfer-Encoding: base64"+enter;
SendBufferstr += "Content-Disposition: attachment;"+enter;
SendBufferstr += " filename=\"=?"+Charset.ToUpper()+"?B?"+Base64Encode

(filepath.Substring(filepath.LastIndexOf("\\")+1))+"?=\""+enter+enter;
SendBufferstr += GetStream(filepath)+enter+enter;
}
SendBufferstr += "--====="+ (Html?"001_Dragon520636771063_":"001_Dragon303406132050_")

+"=====--"+enter+enter;
}



SendBufferstr += enter + "." + enter;

if(!Dialog(SendBufferstr,"错误信件信息"))
return false;


SendBufferstr="QUIT" + enter;
if(!Dialog(SendBufferstr,"断开连接时错误"))
return false;


ns.Close();
tc.Close();
return true;
}


#endregion

#region
/*
/// <summary>
/// 添加一个密件收件人
/// </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
{
errmsg+="收件人过多";
return false;
}
}


/// <summary>
/// 添加一组密件收件人(不超过10个),参数为字符串数组
/// </summary>
/// <param name="str">保存有收件人地址的字符串数组(不超过10个)</param>
public bool AddRecipientBCC(string[] str)
{
for(int i=0;i<str.Length;i++)
{
if(!AddRecipientBCC(str))
{
return false;
}
}
return true;
}

*/
#endregion
}

#endregion
re: System.String 类的实现代码 blog of mb459 2005-12-10 23:04  
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern String PadHelper(int totalWidth, char paddingChar, bool isRightPadded);

// Determines whether a specified string is a prefix of the current instance
//
/**////
public bool StartsWith(String value) ...{
if (null==value) ...{
throw new ArgumentNullException("value");
}
if (this.Length
return false;
}
return (0==Compare(this,0, value,0, value.Length));
}

// Creates a copy of this string in lower case.
/**////
public String ToLower() ...{
return this.ToLower(CultureInfo.CurrentCulture);
}

// Creates a copy of this string in lower case. The culture is set by culture.
/**////
public String ToLower(CultureInfo culture) ...{
if (culture==null) ...{
throw new ArgumentNullException("culture");
}
return culture.TextInfo.ToLower(this);
}

// Creates a copy of this string in upper case.
/**////
public String ToUpper() ...{
return this.ToUpper(CultureInfo.CurrentCulture);
}

// Creates a copy of this string in upper case. The culture is set by culture.
/**////
public String ToUpper(CultureInfo culture) ...{
if (culture==null) ...{
throw new ArgumentNullException("culture");
}
return culture.TextInfo.ToUpper(this);
}

// Returns this string.
/**////
public override String ToString() ...{
return this;
}

/**////
public String ToString(IFormatProvider provider) ...{
return this;
}

// Method required for the ICloneable interface.
// There's no point in cloning a string since they're immutable, so we simply return this.
/**////
public Object Clone() ...{
return this;
}


// Trims the whitespace from both ends of the string. Whitespace is defined by
// CharacterInfo.WhitespaceChars.
//
/**////
public String Trim() ...{
return this.Trim(WhitespaceChars);
}

//
//
/**////
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern String Insert(int startIndex, String value);

// Replaces all instances of oldChar with newChar.
//
/**////
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern String Replace (char oldChar, char newChar);

// This method contains the same functionality as StringBuilder Replace. The only difference is that
// a new String has to be allocated since Strings are immutable
/**////
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern String Replace (String oldValue, String newValue);

//
//
/**////
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public extern String Remove(int startIndex, int count);


/**////
public static String Format(String format, Object arg0) ...{
return Format(null, format, new Object[] ...{arg0});
}

/**////
public static String Format(String format, Object arg0, Object arg1) ...{
return Format(null, format, new Object[] ...{arg0, arg1});
}

/**////
public static String Format(String format, Object arg0, Object arg1, Object arg2) ...{
return Format(null, format, new Object[] ...{arg0, arg1, arg2});
}



/**////
public static String Format(String format, params Object[] args) ...{
return Format(null, format, args);
}

/**////
public static String Format( IFormatProvider provider, String format, params Object[] args) ...{
if (format == null || args == null)
throw new ArgumentNullException((format==null)?"format":"args");
StringBuilder sb = new StringBuilder(format.Length + args.Length * 8);
sb.AppendFormat(provider,format,args);
return sb.ToString();
}

/**////
public static String Copy (String str) ...{
if (str==null) ...{
throw new ArgumentNullException("str");
}

int length = str.Length;

String result = FastAllocateString(length);
FillString(result, 0, str);
return result;
}

// Used by StringBuilder to avoid data corruption
internal static String InternalCopy (String str) ...{
int length = str.Length;
String result = FastAllocateString(length);
FillStringEx(result, 0, str, length); // The underlying's String can changed length is StringBuilder
return result;
}

/**////
public static String Concat(Object arg0) ...{
if (arg0==null) ...{
return String.Empty;
}
return arg0.ToString();
}

/**////
public static String Concat(Object arg0, Object arg1) ...{
if (arg0==null) ...{
arg0 = String.Empty;
}

if (arg1==null) ...{
arg1 = String.Empty;
}
return Concat(arg0.ToString(), arg1.ToString());
}

/**////
public static String Concat(Object arg0, Object arg1, Object arg2) ...{
if (arg0==null) ...{
arg0 = String.Empty;
}

if (arg1==null) ...{
arg1 = String.Empty;
}

if (arg2==null) ...{
arg2 = String.Empty;
}

return Concat(arg0.ToString(), arg1.ToString(), arg2.ToString());
}

/**////
[CLSCompliant(false)]
public static String Concat(Object arg0, Object arg1, Object arg2, Object arg3, __arglist)
...{
Object[] objArgs;
int argCount;

ArgIterator args = new ArgIterator(__arglist);

//+4 to account for the 4 hard-coded arguments at the beginning of the list.
argCount = args.GetRemainingCount() + 4;

objArgs = new Object[argCount];

//Handle the hard-coded arguments
objArgs[0] = arg0;
objArgs[1] = arg1;
objArgs[2] = arg2;
objArgs[3] = arg3;

//Walk all of the args in the variable part of the argument list.
for (int i=4; i objArgs = TypedReference.ToObject(args.GetNextArg());
}

return Concat(objArgs);
}


/**////
public static String Concat(params Object[] args) ...{
if (args==null) ...{
throw new ArgumentNullException("args");
}

String[] sArgs = new String[args.Length];
int totalLength=0;

for (int i=0; i sArgs = ((args==null)?(String.Empty):(args.ToString()));
totalLength += sArgs.Length;
}
return ConcatArray(sArgs, totalLength);
}


/**////
public static String Concat(String str0, String str1) ...{
if (str0 == null) ...{
if (str1==null) ...{
return String.Empty;
}
return str1;
}

if (str1==null) ...{
return str0;
}

int str0Length = str0.Length;

String result = FastAllocateString(str0Length + str1.Length);

FillStringChecked(result, 0, str0);
FillStringChecked(result, str0Length, str1);

return result;
}

/**////
public static String Concat(String str0, String str1, String str2) ...{
if (str0==null && str1==null && str2==null) ...{
return String.Empty;
}

if (str0==null) ...{
str0 = String.Empty;
}

if (str1==null) ...{
str1 = String.Empty;
}

if (str2 == null) ...{
str2 = String.Empty;
}

int totalLength = str0.Length + str1.Length + str2.Length;

String result = FastAllocateString(totalLength);
FillStringChecked(result, 0, str0);
FillStringChecked(result, str0.Length, str1);
FillStringChecked(result, str0.Length + str1.Length, str2);

return result;
}

/**////
public static String Concat(String str0, String str1, String str2, String str3) ...{
if (str0==null && str1==null && str2==null && str3==null) ...{
return String.Empty;
}

if (str0==null) ...{
str0 = String.Empty;
}

if (str1==null) ...{
str1 = String.Empty;
}

if (str2 == null) ...{
str2 = String.Empty;
}

if (str3 == null) ...{
str3 = String.Empty;
}

int totalLength = str0.Length + str1.Length + str2.Length + str3.Length;

String result = FastAllocateString(totalLength);
FillStringChecked(result, 0, str0);
FillStringChecked(result, str0.Length, str1);
FillStringChecked(result, str0.Length + str1.Length, str2);
FillStringChecked(result, str0.Length + str1.Length + str2.Length, str3);

return result;
}

private static String ConcatArray(String[] values, int totalLength) ...{
String result = FastAllocateString(totalLength);
int currPos=0;

for (int i=0; i BCLDebug.Assert((currPos + values.Length <= totalLength),
"[String.ConcatArray](currPos + values.Length <= totalLength)");

FillStringChecked(result, currPos, values);
currPos+=values.Length;
}

return result;
}

private static String[] CopyArrayOnNull(String[] values, out int totalLength) ...{
totalLength = 0;

String[] outValues = new String[values.Length];

for (int i=0; i outValues = ((values==null)?String.Empty:values);
totalLength += outValues.Length;
}
return outValues;
}

/**////
public static String Concat(params String[] values) ...{
int totalLength=0;

if (values==null) ...{
throw new ArgumentNullException("values");
}

for (int i=0; i if (values==null) ...{
values = CopyArrayOnNull(values, out totalLength);
break;
} else ...{
totalLength += values.Length;
}
}

return ConcatArray(values, totalLength);
}

/**////
public static String Intern(String str) ...{
if (str==null) ...{
throw new ArgumentNullException("str");
}
return Thread.GetDomain().GetOrInternString(str);
}

/**////
public static String IsInterned(String str) ...{
if (str==null) ...{
throw new ArgumentNullException("str");
}
return Thread.GetDomain().IsStringInterned(str);
}


//
// IValue implementation
//

/**////
public TypeCode GetTypeCode() ...{
return TypeCode.String;
}

/**////
///
bool IConvertible.ToBoolean(IFormatProvider provider) ...{
return Convert.ToBoolean(this, provider);
}

/**////
///
char IConvertible.ToChar(IFormatProvider provider) ...{
return Convert.ToChar(this, provider);
}

/**////
///
[CLSCompliant(false)]
sbyte IConvertible.ToSByte(IFormatProvider provider) ...{
return Convert.ToSByte(this, provider);
}

/**////
///
byte IConvertible.ToByte(IFormatProvider provider) ...{
return Convert.ToByte(this, provider);
}

/**////
///
short IConvertible.ToInt16(IFormatProvider provider) ...{
return Convert.ToInt16(this, provider);
}

/**////
///
[CLSCompliant(false)]
ushort IConvertible.ToUInt16(IFormatProvider provider) ...{
return Convert.ToUInt16(this, provider);
}

/**////
///
int IConvertible.ToInt32(IFormatProvider provider) ...{
return Convert.ToInt32(this, provider);
}

/**////
///
[CLSCompliant(false)]
uint IConvertible.ToUInt32(IFormatProvider provider) ...{
return Convert.ToUInt32(this, provider);
}

/**////
///
long IConvertible.ToInt64(IFormatProvider provider) ...{
return Convert.ToInt64(this, provider);
}

/**////
///
[CLSCompliant(false)]
ulong IConvertible.ToUInt64(IFormatProvider provider) ...{
return Convert.ToUInt64(this, provider);
}

/**////
///
float IConvertible.ToSingle(IFormatProvider provider) ...{
return Convert.ToSingle(this, provider);
}

/**////
///
double IConvertible.ToDouble(IFormatProvider provider) ...{
return Convert.ToDouble(this, provider);
}

/**////
///
Decimal IConvertible.ToDecimal(IFormatProvider provider) ...{
return Convert.ToDecimal(this, provider);
}

/**////
///
DateTime IConvertible.ToDateTime(IFormatProvider provider) ...{
return Convert.ToDateTime(this, provider);
}

/**////
///
Object IConvertible.ToType(Type type, IFormatProvider provider) ...{
return Convert.DefaultToType((IConvertible)this, type, provider);
}

// Is this a string that can be compared quickly (that is it has only characters > 0x80
// and not a - or '
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal extern bool IsFastSort();

/**////
unsafe internal void SetChar(int index, char value)
...{
#if _DEBUG
BCLDebug.Assert(ValidModifiableString(), "Modifiable string must not have highChars flags set");
#endif

//Bounds check and then set the actual bit.
if ((UInt32)index >= (UInt32)Length)
throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_Index"));

fixed (char *p = &this.m_firstChar) ...{
// Set the character.
p[index] = value;
}
}

#if _DEBUG
// Only used in debug build. Insure that the HighChar state information for a string is not set as known
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern bool ValidModifiableString();
#endif

/**////
unsafe internal void AppendInPlace(char value,int currentLength)
...{
BCLDebug.Assert(currentLength < m_arrayLength, "[String.AppendInPlace(char)currentLength < m_arrayLength");
#if _DEBUG
BCLDebug.Assert(ValidModifiableString(), "Modifiable string must not have highChars flags set");
#endif

fixed (char *p = &this.m_firstChar)
...{
// Append the character.
p[currentLength] = value;
p[++currentLength] = '\0';
m_stringLength = currentLength;
}
}


/**////
unsafe internal void AppendInPlace(char value, int repeatCount, int currentLength)
...{
BCLDebug.Assert(currentLength+repeatCount < m_arrayLength, "[String.AppendInPlace]currentLength+repeatCount < m_arrayLength");
#if _DEBUG
BCLDebug.Assert(ValidModifiableString(), "Modifiable string must not have highChars flags set");
#endif

int newLength = currentLength + repeatCount;


fixed (char *p = &this.m_firstChar)
...{
int i;
for (i=currentLength; i p = value;
}
p = '\0';
}
this.m_stringLength = newLength;
}

/**////
internal unsafe void AppendInPlace(String value, int currentLength) ...{
BCLDebug.Assert(value!=null, "[String.AppendInPlace]value!=null");
BCLDebug.Assert(value.Length + currentLength < this.m_arrayLength, "[String.AppendInPlace]Length is wrong.");
#if _DEBUG
BCLDebug.Assert(ValidModifiableString(), "Modifiable string must not have highChars flags set");
#endif

FillString(this, currentLength, value);
SetLength(currentLength + value.Length);
NullTerminate();
}

internal void AppendInPlace(String value, int startIndex, int count, int currentLength) ...{
BCLDebug.Assert(value!=null, "[String.AppendInPlace]value!=null");
BCLDebug.Assert(count + currentLength < this.m_arrayLength, "[String.AppendInPlace]count + currentLength < this.m_arrayLength");
BCLDebug.Assert(count>=0, "[String.AppendInPlace]count>=0");
BCLDebug.Assert(startIndex>=0, "[String.AppendInPlace]startIndex>=0");
BCLDebug.Assert(startIndex <= (value.Length - count), "[String.AppendInPlace]startIndex <= (value.Length - count)");
#if _DEBUG
BCLDebug.Assert(ValidModifiableString(), "Modifiable string must not have highChars flags set");
#endif

FillSubstring(this, currentLength, value, startIndex, count);
SetLength(currentLength + count);
NullTerminate();
}

internal unsafe void AppendInPlace(char *value, int count,int currentLength) ...{
BCLDebug.Assert(value!=null, "[String.AppendInPlace]value!=null");
BCLDebug.Assert(count + currentLength < this.m_arrayLength, "[String.AppendInPlace]count + currentLength < this.m_arrayLength");
BCLDebug.Assert(count>=0, "[String.AppendInPlace]count>=0");
#if _DEBUG
BCLDebug.Assert(ValidModifiableString(), "Modifiable string must not have highChars flags set");
#endif
fixed(char *p = &this.m_firstChar) ...{
int i;
for (i=0; i p[currentLength+i] = value;
}
}
SetLength(currentLength + count);
NullTerminate();
}


/**////
internal unsafe void AppendInPlace(char[] value, int start, int count, int currentLength) ...{
BCLDebug.Assert(value!=null, "[String.AppendInPlace]value!=null");
BCLDebug.Assert(count + currentLength < this.m_arrayLength, "[String.AppendInPlace]Length is wrong.");
BCLDebug.Assert(value.Length-count>=start, "[String.AppendInPlace]value.Length-count>=start");
#if _DEBUG
BCLDebug.Assert(ValidModifiableString(), "Modifiable string must not have highChars flags set");
#endif

FillStringArray(this, currentLength, value, start, count);
this.m_stringLength = (currentLength + count);
this.NullTerminate();
}


/**////
unsafe internal void ReplaceCharInPlace(char oldChar, char newChar, int startIndex, int count,int currentLength) ...{
BCLDebug.Assert(startIndex>=0, "[String.ReplaceCharInPlace]startIndex>0");
BCLDebug.Assert(startIndex<=currentLength, "[String.ReplaceCharInPlace]startIndex>=Length");
BCLDebug.Assert((startIndex<=currentLength-count), "[String.ReplaceCharInPlace]count>0 && startIndex<=currentLength-count");
#if _DEBUG
BCLDebug.Assert(ValidModifiableString(), "Modifiable string must not have highChars flags set");
#endif

int endIndex = startIndex+count;

fixed (char *p = &this.m_firstChar) ...{
for (int i=startIndex;i if (p==oldChar) ...{
p=newChar;
}
}
}
}


/**////
internal static String GetStringForStringBuilder(String value, int capacity) ...{
BCLDebug.Assert(value!=null, "[String.GetStringForStringBuilder]value!=null");
BCLDebug.Assert(capacity>=value.Length, "[String.GetStringForStringBuilder]capacity>=value.Length");

String newStr = FastAllocateString(capacity);
if (value.Length==0) ...{
newStr.m_stringLength=0;
newStr.m_firstChar='\0';
return newStr;
}
FillString(newStr, 0, value);
newStr.m_stringLength = value.m_stringLength;
return newStr;
}

/**////
private unsafe void NullTerminate() ...{
fixed(char *p = &this.m_firstChar) ...{
p[m_stringLength] = '\0';
}
}

/**////
unsafe internal void ClearPostNullChar() ...{
int newLength = Length+1;
if (newLength
fixed(char *p = &this.m_firstChar) ...{
p[newLength] = '\0';
}
}
}

/**////
internal void SetLength(int newLength) ...{
BCLDebug.Assert(newLength <= m_arrayLength, "newLength<=m_arrayLength");
m_stringLength = newLength;
}



/**////
public CharEnumerator GetEnumerator() ...{
BCLDebug.Perf(false, "Avoid using String's CharEnumerator until C# special cases foreach on String - use the indexed property on String instead.");
return new CharEnumerator(this);
}

/**////
///
IEnumerator IEnumerable.GetEnumerator() ...{
BCLDebug.Perf(false, "Avoid using String's CharEnumerator until C# special cases foreach on String - use the indexed property on String instead.");
return new CharEnumerator(this);
}

//
// This is just designed to prevent compiler warnings.
// This field is used from native, but we need to prevent the compiler warnings.
//
#if _DEBUG
private void DontTouchThis() ...{
m_arrayLength = 0;
m_stringLength = 0;
m_firstChar = m_firstChar;
}
#endif

internal unsafe void InternalSetCharNoBoundsCheck(int index, char value) ...{
fixed (char *p = &this.m_firstChar) ...{
p[index] = value;
}
}

// Copies the source String (byte buffer) to the destination IntPtr memory allocated with len bytes.
internal unsafe static void InternalCopy(String src, IntPtr dest,int len)
...{
if (len == 0)
return;
fixed(char* charPtr = &src.m_firstChar) ...{
byte* srcPtr = (byte*) charPtr;
byte* dstPtr = (byte*) dest.ToPointer();
System.IO.__UnmanagedMemoryStream.memcpyimpl(srcPtr, dstPtr, len);
}
}

// memcopies characters inside a String.
internal unsafe static void InternalMemCpy(String src, int srcOffset, String dst, int destOffset, int len)
...{
if (len == 0)
return;
fixed(char* srcPtr = &src.m_firstChar) ...{
fixed(char* dstPtr = &dst.m_firstChar) ...{
System.IO.__UnmanagedMemoryStream.memcpyimpl((byte*)(srcPtr + srcOffset), (byte*)(dstPtr + destOffset), len);
}
}
}



internal unsafe static void revmemcpyimpl(byte* src, byte* dest, int len) ...{
if (len == 0)
return;

dest += len;
src += len;

if (((long)src & 3) != 0)
...{
do...{
dest--;
src--;
len--;
*dest = *src;
} while (len > 0 && ((long)src & 3) != 0);
}

if (len >= 16)...{
len -= 16;
do...{
dest -= (byte*)16;
src -= (byte*)16;
((int*)dest)[3] = ((int*)src)[3];
((int*)dest)[2] = ((int*)src)[2];
((int*)dest)[1] = ((int*)src)[1];
((int*)dest)[0] = ((int*)src)[0];

} while ((len -= 16) >= 0);
}
if ((len & 8) > 0) ...{
dest -= (byte*)8;
src -= (byte*)8;
((int*)dest)[1] = ((int*)src)[1];
((int*)dest)[0] = ((int*)src)[0];
}
if ((len & 4) > 0) ...{
dest -= (byte*)4;
src -= (byte*)4;
((int*)dest)[0] = ((int*)src)[0];
}
if ((len & 2) != 0) ...{
dest -= (byte*)2;
src -= (byte*)2;
((short*)dest)[0] = ((short*)src)[0];
}
if ((len & 1) != 0) ...{
dest--;
src--;
*dest = *src;
}
}




// Copies the source String (byte buffer) to the destination IntPtr memory allocated with len bytes.
internal unsafe static void InternalCopy(String src, byte[] dest,int len)
...{
if (len == 0)
return;
fixed(char* charPtr = &src.m_firstChar) ...{
fixed(byte* destPtr = dest) ...{
byte* srcPtr = (byte*) charPtr;
System.IO.__UnmanagedMemoryStream.memcpyimpl(srcPtr, destPtr, len);
}
}
}

internal unsafe void InsertInPlace(int index, String value, int repeatCount, int currentLength, int requiredLength) ...{
BCLDebug.Assert(requiredLength < m_arrayLength, "[String.InsertString] requiredLength < m_arrayLength");
BCLDebug.Assert(index + value.Length * repeatCount < m_arrayLength, "[String.InsertString] index + value.Length * repeatCount < m_arrayLength");
#if _DEBUG
BCLDebug.Assert(ValidModifiableString(), "Modifiable string must not have highChars flags set");
#endif
//Copy the old characters over to make room and then insert the new characters.
fixed(char* srcPtr = &this.m_firstChar) ...{
fixed(char* valuePtr = &value.m_firstChar) ...{
revmemcpyimpl((byte*)(srcPtr + index),(byte*)(srcPtr + index + value.Length * repeatCount), (currentLength - index) * sizeof(char));
for (int i=0; i System.IO.__UnmanagedMemoryStream.memcpyimpl((byte*)valuePtr, (byte*)(srcPtr + index + i * value.Length), value.Length * sizeof(char));
}
}
srcPtr[requiredLength] = '\0';
}
this.m_stringLength = requiredLength;
}


}
}
re: 一篇让人流泪的爱情故事(转) 强子 2005-11-15 22:39  
看完了你的故事我什么都说不出来,你是一个好男儿,她也是一个好女孩子,她这样的女孩子我想几乎没有了。可是命运弄人,你做出的牺牲她会懂的,如果她对你的是真爱的话,我相信她不会出国了,难道出国才会幸福吗,只要两个人真心相爱我想既使过得清贫点也是甜的。也许我的这种观念有些过时吧,不过我还是祝福你们最终能走到一起去,祝福你们吧!
re: 一篇让人流泪的爱情故事(转) blog of mb459 2005-05-09 16:27  
其实爱一个人真的不一定要拥有。就像是一本好书不一定非要买回家。爱的过程本身就是一种幸福,没有奢望回报,也根本就不会有回报,只是想看到她的微笑,只是想听到她的声音,只是想听别人说她过得很幸福。谁说相思一定是苦,谁说得到一定是幸福,我就把这份爱埋在心灵深处,让岁月把它酿成一坛足以醉你一生一世的酒。
re: 一篇让人流泪的爱情故事(转) blog of mb459 2005-05-09 16:18  
生命自会有安排,你的选择舍弃了你的感情,或许你是对的.但你却无法忘记这一段真爱,没办法,你已经选择了,其实你应该自信,相信爱情的力量,相信自己会让一切变的更美好.干什么不相信未来的你会是一个生活中的强者.你的未来不是梦,只缺阳光.