用c#写的smtp邮件发送类-asp.net教程
转载自:互联网 作者:cd3c.com
您正在看的asp.net教程是:用c#写的smtp邮件发送类。
//**********************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
{
///
/// 邮件内容
///
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;
///
/// 获取或设置发件人
///
public string Sender
{
get{return this.sender;}
set{this.sender=value;}
}
///
/// 获取收件人地址集合
///
public StringCollection Receivers
{
get{return this.receivers;}
}
///
/// 获取或设置邮件主题
///
public string Subject
{
get{return this.subject;}
set{this.subject=value;}
}
///
/// 获取或设置邮件传送者
///
public string XMailer
{
get{return this.xMailer;}
set{this.xMailer=value;}
}
///
/// 获取附件列表
///
public StringCollection Attachments
{
get{return this.attachments;}
}
///
/// 获取或设置邮件的编码方式
///
public MailEncodings MailEncoding
{
get{return this.mailEncoding;}
set{this.mailEncoding=value;}
}
///
/// 获取或设置邮件格式
///
public MailTypes MailType
{
get{return this.mailType;}
set{this.mailType=value;}
}
///
/// 获取或设置邮件正文
///
public byte[] MailBody
{
get{return this.mailBody;}
set{this.mailBody=value;}
}
}
///
/// 邮件编码
///
public enum MailEncodings
{
GB2312,
ASCII,
Unicode,
UTF8
}
///
/// 邮件格式
///
public enum MailTypes
{
Html,
Text
}
///
/// smtp服务器的验证方式
///
public enum SmtpValidateTypes
{
///
/// 不需要验证
///
None,
///
/// 通用的auth login验证
///
Login,
///
/// 通用的auth plain验证
///
Plain,
///
/// CRAM-MD5验证
///
CRAMMD5
}
///
/// 邮件发送类
///
public class KSN_Smtp
{
#region "member fields"
///
/// 连接对象
///
private TcpClient tc;
///
/// 网络流
///
private NetworkStream ns;
///
/// 错误的代码
[1] [2] [3] [4] [5] [6] [7] 下一篇
