日期:2011-10-16  浏览次数:20488 次

//**********************Created by Chen**************************
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Collections;
using System.Collections.Specialized;
using KSN.Exceptions;
using KSN.Validate;
namespace KSN.Web.Mail
{
/// <summary>
/// 邮件内容
/// </summary>
public class MailMessage
{
private string sender=null;
private StringCollection receivers=new StringCollection();
private string subject="";
private string xMailer="";
private StringCollection attachments=new StringCollection();
private MailEncodings mailEncoding=MailEncodings.GB2312;
private MailTypes mailType=MailTypes.Html;
private byte[] mailBody=null;
/// <summary>
/// 获取或设置发件人
/// </summary>
public string Sender
{
get{return this.sender;}
set{this.sender=value;}
}
/// <summary>
/// 获取收件人地址集合
/// </summary>
public StringCollection Receivers
{
get{return this.receivers;}
}
/// <summary>
/// 获取或设置邮件主题
/// </summary>
public string Subject
{
get{return this.subject;}
set{this.subject=value;}
}
/// <summary>
/// 获取或设置邮件传送者
/// </summary>
public string XMailer
{
get{return this.xMailer;}
set{this.xMailer=value;}
}
/// <summary>
/// 获取附件列表
/// </summary>
public StringCollection Attachments
{
get{return this.attachments;}
}
/// <summary>
/// 获取或设置邮件的编码方式
/// </summary>
public MailEncodings MailEncoding
{
get{return this.mailEncoding;}
set{this.mailEncoding=value;}
}
/// <summary>
/// 获取或设置邮件格式
/// </summary>
public MailTypes MailType
{
get{return this.mailType;}
set{this.mailType=value;}
}
/// <summary>
/// 获取或设置邮件正文
/// </summary>
public byte[] MailBody
{
get{return this.mailBody;}
set{this.mailBody=value;}
}
}
/// <summary>
/// 邮件编码
/// </summary>
public enum MailEncodings
{
GB2312,
ASCII,
Unicode,
UTF8
}
/// <summary>
/// 邮件格式
/// </summary>
public enum MailTypes
{
Html,
Text
}
/// <summary>
/// smtp服务器的验证方式
/// </summary>
public enum SmtpValidateTypes
{
/// <summary>
/// 不需要验证
/// </summary>
None,
/// <summary>
/// 通用的auth login验证
/// </summary>
Login,
/// <summary>
/// 通用的auth plain验证
/// </summary>
Plain,
/// <summary>
/// CRAM-MD5验证
/// </summary>
CRAMMD5
}
/// <summary>
/// 邮件发送类
/// </summary>
public class KSN_Smtp
{
#region "member fields"
/// <summary>
/// 连接对象
/// </summary>
private TcpClient tc;
/// <summary>
/// 网络流
/// </summary>
private NetworkStream ns;
/// <summary>
/// 错误的代码字典
/// </summary>
private StringDictionary errorCodes=new StringDictionary();
/// <summary>
/// 操作执行成功后的响应代码字典
/// </summary>
private StringDictionary rightCodes=new StringDictionary();
/// <summary>
/// 执行过程中错误的消息
/// </summary>
private string errorMessage="";
/// <summary>
/// 记录操作日志
/// </summary>
private string logs="";
/// <summary>
/// 主机登陆的验证方式
/// </summary><