转自:http://industry.ccidnet.com/art/1077/20031105/684343_1.html
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>
/// 邮件服务器域名和验证信息
/// 形