用c#写的smtp邮件发送类__教程 |
|
日期:2007-5-20 1:21:25 人气:114 [大 中 小] |
|
|
|
mail.MailEncoding.ToString()+"\""+CRLF; message+="Content-Transfer-Encoding:base64"+CRLF+CRLF; if(mail.MailBody!=null) message+=Convert.ToBase64String(mail.MailBody,0,mail.MailBody.Length)+CRLF+CRLF+CRLF+"."+CRLF; } else//Html格式 { message+="Content-Type:multipart/alertnative;"+CRLF+" ".PadRight(8,' ')+"boundary" +"=\"=====003_Dragon310083331177_=====\""+CRLF+CRLF+CRLF; message+="This is a multi-part message in MIME format"+CRLF+CRLF; message+="--=====003_Dragon310083331177_====="+CRLF; message+="Content-Type:text/html;"+CRLF+" ".PadRight(8,' ')+"charset=\""+ mail.MailEncoding.ToString().ToLower()+"\""+CRLF; message+="Content-Transfer-Encoding:base64"+CRLF+CRLF; if(mail.MailBody!=null) message+=Convert.ToBase64String(mail.MailBody,0,mail.MailBody.Length)+CRLF+CRLF; message+="--=====003_Dragon310083331177_=====--"+CRLF+CRLF+CRLF+"."+CRLF; } } else//有附件 { //处理要在邮件中显示的每个附件的数据 StringCollection attatchmentDatas=new StringCollection(); foreach(string path in mail.Attachments) { if(!File.Exists(path)) { this.setError("指定的附件没有找到"+path); } else { //得到附件的字节流 FileInfo file=new FileInfo(path); FileStream fs=new FileStream(path,FileMode.Open,FileAccess.Read); if(fs.Length>(long)int.MaxValue) { this.setError("附件的大小超出了最大限制"); } byte[] file_b=new byte[(int)fs.Length]; fs.Read(file_b,0,file_b.Length); fs.Close(); string attatchmentMailStr="Content-Type:application/octet-stream;"+CRLF+" ".PadRight(8,' ')+"name="+ "\""+file.Name+"\""+CRLF; attatchmentMailStr+="Content-Transfer-Encoding:base64"+CRLF; attatchmentMailStr+="Content-Disposition:attachment;"+CRLF+" ".PadRight(8,' ')+"filename="+ "\""+file.Name+"\""+CRLF+CRLF; attatchmentMailStr+=Convert.ToBase64String(file_b,0,file_b.Length)+CRLF+CRLF; attatchmentDatas.Add(attatchmentMailStr); } } //设置邮件信息 if(mail.MailType==MailTypes.Text) //文本格式 { message+="Content-Type:multipart/mixed;"+CRLF+" ".PadRight(8,' ')+"boundary=\"=====001_Dragon320037612222_=====\"" +CRLF+CRLF; message+="This is a multi-part message in MIME format."+CRLF+CRLF; message+="--=====001_Dragon320037612222_====="+CRLF; message+="Content-Type:text/plain;"+CRLF+" ".PadRight(8,' ')+"charset=\""+mail.MailEncoding.ToString().ToLower()+"\""+CRLF; message+="Content-Transfer-Encoding:base64"+CRLF+CRLF; if(mail.MailBody!=null) message+=Convert.ToBase64String(mail.MailBody,0,mail.MailBody.Length)+CRLF; foreach(string s in attatchmentDatas) { message+="--=====001_Dragon320037612222_====="+CRLF+s+CRLF+CRLF; } message+="--=====001_Dragon320037612222_=====--"+CRLF+CRLF+CRLF+"."+CRLF; } else { message+="Content-Type:multipart/mixed;"+CRLF+" ".PadRight(8,' ')+"boundary=\"=====001_Dragon255511664284_=====\"" +CRLF+CRLF; message+="This is a multi-part message in MIME format."+CRLF+CRLF; |
|
出处:本站原创 作者:佚名 |
|
|