改进了的一个邮件发送类

/******************************************************
FileName:
Copyright (c) 2003-xxxx *********公司技术开发部
Writer:
create Date:2004-12-20
Rewriter:
Rewrite Date:
Impact:
Main Content:(Function Name、parameters、returns)
支持ESMTP, 多附件
******************************************************/

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

namespace Edu.Stu.Common.Mail
{
///<summary>
/// Module ID:0005
/// Depiction:发送邮件,支持ESMTP, 多附件
/// Wreter:Nick
/// Create Date;2004-12-20
///</summary>
public class MailSender
{

#region "Fields"
private string m_strFromName = "";
private string[] m_strTo = null;
private string m_strFrom = "";
private string m_strPassWord = "";
private string m_strUserName = "";
private int m_iPort = 25;
private string m_strServer = "";
private int m_iPriority = 3;
private string m_strEncoding = "8bit";
private string m_strLanguageEncoding = "GB2312";
private bool m_bIsHtml = true;
private string m_strHtmlBody = "";
private string m_strTxtBody = "";
private string m_strSubject = "";
private string m_strToName = "";
private ArrayList m_alAttachments = new ArrayList ();
#endregion

#region "Propertes"
/// <summary>
/// SMTP服务器域名
/// </summary>
public string Server
{
get { return m_strServer; }
set { if (value != m_strServer) m_strServer = value; }
}

/// <summary>
/// SMTP服务器端口 [默认为25]
/// </summary>
public int Port {
get { return m_iPort; }
set { if (value != m_iPort) m_iPort = value; }
}

/// <summary>
/// 用户名 [如果需要身份验证的话]
/// </summary>
public string UserName
{
get { return m_strUserName; }
set { if (value != m_strUserName) m_strUserName = value; }
}

/// <summary>
/// 密码 [如果需要身份验证的话]
/// </summary>
public string Password
{
get { return m_strPassWord; }
set { if (value != m_strPassWord) m_strPassWord = value; }
}

/// <summary>
/// 发件人地址
/// </summary>
public string From
{
get { return m_strFrom; }
set { if (value != m_strFrom) m_strFrom = value;}
}

/// <summary>
/// 收件人地址
/// </summary>
public string[] To
{
get { return m_strTo; }
set { if (value != m_strTo) m_strTo = value;}
}

/// <summary>
/// 发件人姓名
/// </summary>
public string FromName
{
get { return m_strFromName; }
set { if (value != m_strFromName) m_strFromName = value; }
}

/// <summary>
/// 收件人姓名
/// </summary>
public string ToName
{
get { return m_strToName; }
set { if (value != m_strToName) m_strToName = value; }
}

/// <summary>
/// 邮件的主题
/// </summary>
public string Subject
{
get { return m_strSubject; }
set { if (value != m_strSubject) m_strSubject = value; }
}

/// <summary>
/// 邮件正文
/// </summary>
public string Body
{
get { return m_strTxtBody; }
set { if (value != m_strTxtBody) m_strTxtBody = value; }
}

/// <summary>
/// 超文本格式的邮件正文
/// </summary>
public string HtmlBody {
get { return m_strHtmlBody; }
set { if (value != m_strHtmlBody) m_strHtmlBody = value; }
}

/// <summary>
/// 是否是html格式的邮件
/// </summary>
public bool IsHtml
{
get { return m_bIsHtml; }
set { if (value != m_bIsHtml) m_bIsHtml = value; }
}

/// <summary>
/// 语言编码 [默认为GB2312]
/// </summary>
public string LanguageEncoding
{
get { return m_strLanguageEncoding; }
set { if (value != m_strLanguageEncoding) m_strLanguageEncoding = value; }
}

/// <summary>
/// 邮件编码 [默认为8bit]
/// </summary>
public string MailEncoding
{
get { return m_strEncoding; }
set { if (value != m_strEncoding) m_strEncoding = value; }
}

/// <summary>
/// 邮件优先级 [默认为3]
/// </summary>
public int Priority
{
get { return m_iPriority; }
set { if (value != m_iPriority) m_iPriority = value; }
}

/// <summary>
/// 附件 [AttachmentInfo]
/// </summary>
public IList Attachments
{
get { return m_alAttachments; }
// set { if (value != m_alAttachments) m_alAttachments = value; }
}

#endregion

#region "Struct AttachmentInfo"
/// <summary>
/// 附件信息
/// </summary>
public struct AttachmentInfo
{
/// <summary>
/// 附件的文件名 [如果输入路径,则自动转换为文件名]
/// </summary>
public string FileName
{
get { return fileName; }
set { fileName = Path.GetFileName(value); }
} private string fileName;

/// <summary>
/// 附件的内容 [由经Base64编码的字节组成]
/// </summary>
public string Bytes
{
get { return bytes; }
set { if (value != bytes) bytes = value; }
} private string bytes;

/// <summary>
/// 从流中读取附件内容并构造
/// </summary>
/// <param name="p_strFileName">附件的文件名</param>
/// <param name="p_stream">流</param>
public AttachmentInfo (string p_strFileName, Stream p_stream)
{
fileName = Path.GetFileName (p_strFileName);
byte[] by = new byte [p_stream.Length];
p_stream.Read (by,0,(int)p_stream.Length); // 读取文件内容
//格式转换
bytes = Convert.ToBase64String (by); // 转化为base64编码
}

/// <summary>
/// 按照给定的字节构造附件
/// </summary>
/// <param name="p_strFileName">附件的文件名</param>
/// <param name="ibytes">附件的内容 [字节]</param>
public AttachmentInfo (string p_strFileName, byte[] ibytes)
{
fileName = Path.GetFileName (p_strFileName);
bytes = Convert.ToBase64String (ibytes); // 转化为base64编码
}

/// <summary>
/// 从文件载入并构造
/// </summary>
/// <param name="p_strPath"></param>
public AttachmentInfo (string p_strPath)
{
fileName = Path.GetFileName (p_strPath);
FileStream file = new FileStream (p_strPath, FileMode.Open);
byte[] by = new byte [file.Length];
file.Read (by,0,(int)file.Length); // 读取文件内容
//格式转换
bytes = Convert.ToBase64String (by); // 转化为base64编码
file.Close ();
}
}
#endregion

#region "Functions"
/// <summary>
/// 发送邮件
/// </summary>
private void SendMail()
{
// 创建TcpClient对象, 并建立连接
TcpClient tcpNewClient = null;
try
{
tcpNewClient = new TcpClient (m_strServer, m_iPort);
}
catch (Exception)
{
throw new Exception ("无法连接服务器");
}

ReadString (tcpNewClient.GetStream());//获取连接信息

// 开始进行服务器认证
// 如果状态码是250则表示操作成功
if (!Command (tcpNewClient.GetStream(), "EHLO Localhost", "250"))
{
tcpNewClient.Close();
throw new Exception ("登陆阶段失败");
}

if (m_strUserName != "")
{
// 需要身份验证
if (!Command (tcpNewClient.GetStream(), "AUTH LOGIN", "334"))
{
tcpNewClient.Close();
throw new Exception ("身份验证阶段失败");
}

// 此处将username转换为Base64码
string nameB64 = ToBase64 (m_strUserName);
if (!Command (tcpNewClient.GetStream(), nameB64, "334"))
{
tcpNewClient.Close();
throw new Exception ("身份验证阶段失败");
}

// 此处将m_strPassWord转换为Base64码
string passB64 = ToBase64 (m_strPassWord);
if (!Command (tcpNewClient.GetStream(), passB64, "235"))
{
tcpNewClient.Close();
throw new Exception ("身份验证阶段失败");
}
}

// 准备发送
WriteString (tcpNewClient.GetStream(), "mail From: " + m_strFrom);
for(int i=0;i<m_strTo.Length;i++)
{
WriteString (tcpNewClient.GetStream(), "rcpt m_strTo: " + m_strTo[i]);
}
WriteString (tcpNewClient.GetStream(), "data");

// 发送邮件头
WriteString (tcpNewClient.GetStream(), "Date: " + DateTime.Now); // 时间
WriteString (tcpNewClient.GetStream(), "From: " + m_strFromName + "<" + m_strFrom + ">"); // 发件人
WriteString (tcpNewClient.GetStream(), "Subject: " + m_strSubject); // 主题
WriteString (tcpNewClient.GetStream(), "To:" + m_strToName + "<" + m_strTo + ">"); // 收件人

//邮件格式
WriteString (tcpNewClient.GetStream(), "Content-Type: multipart/mixed; boundary=\"unique-boundary-1\"");
WriteString (tcpNewClient.GetStream(), "Reply-To:" + m_strFrom); // 回复地址
WriteString (tcpNewClient.GetStream(), "X-Priority:" + m_iPriority); // 优先级
WriteString (tcpNewClient.GetStream(), "MIME-Version:1.0"); // MIME版本

// 数据ID,随意
// WriteString (tcpNewClient.GetStream(), "Message-Id: " + DateTime.Now.ToFileTime() + "@security.com");
WriteString (tcpNewClient.GetStream(), "Content-Transfer-Encoding:" + m_strEncoding); // 内容编码
WriteString (tcpNewClient.GetStream(), "X-Mailer:JcPersonal.Utility.MailSender"); // 邮件发送者
WriteString (tcpNewClient.GetStream(), "");

WriteString (tcpNewClient.GetStream(), ToBase64 ("This is a multi-part message in MIME format."));
WriteString (tcpNewClient.GetStream(), "");

// 从此处开始进行分隔输入
WriteString (tcpNewClient.GetStream(), "--unique-boundary-1");

// 在此处定义第二个分隔符
WriteString (tcpNewClient.GetStream(), "Content-Type: multipart/alternative;Boundary=\"unique-boundary-2\"");
WriteString (tcpNewClient.GetStream(), "");

if(!m_bIsHtml)
{
// 文本信息
WriteString (tcpNewClient.GetStream(), "--unique-boundary-2");
WriteString (tcpNewClient.GetStream(), "Content-Type: text/plain;charset=" + m_strLanguageEncoding);
WriteString (tcpNewClient.GetStream(), "Content-Transfer-Encoding:" + m_strEncoding);
WriteString (tcpNewClient.GetStream(), "");
WriteString (tcpNewClient.GetStream(), m_strTxtBody);
WriteString (tcpNewClient.GetStream(), "");//一个部分写完之后就写如空信息,分段
WriteString (tcpNewClient.GetStream(), "--unique-boundary-2--");//分隔符的结束符号,尾巴后面多了--
WriteString (tcpNewClient.GetStream(), "");
}
else
{
//html信息
WriteString (tcpNewClient.GetStream(), "Content-Type: multipart/mixed");
WriteString (tcpNewClient.GetStream(), "--unique-boundary-2");
WriteString (tcpNewClient.GetStream(), "Content-Type: text/html;charset=" + m_strLanguageEncoding);
WriteString (tcpNewClient.GetStream(), "Content-Transfer-Encoding:" + m_strEncoding);
WriteString (tcpNewClient.GetStream(), "");
WriteString (tcpNewClient.GetStream(), m_strHtmlBody);
WriteString (tcpNewClient.GetStream(), "");
WriteString (tcpNewClient.GetStream(), "--unique-boundary-2--");//分隔符的结束符号,尾巴后面多了--
WriteString (tcpNewClient.GetStream(), "");
}

// 发送附件
// 对文件列表做循环
for (int i = 0; i < m_alAttachments.Count; i++)
{
WriteString (tcpNewClient.GetStream(), "--unique-boundary-1"); // 邮件内容分隔符
WriteString (tcpNewClient.GetStream(), "Content-Type: application/octet-stream;name=\"" + ((AttachmentInfo)m_alAttachments[i]).FileName + "\""); // 文件格式
WriteString (tcpNewClient.GetStream(), "Content-Transfer-Encoding: base64"); // 内容的编码
WriteString (tcpNewClient.GetStream(), "Content-Disposition:attachment;filename=\"" + ((AttachmentInfo)m_alAttachments[i]).FileName + "\""); // 文件名
WriteString (tcpNewClient.GetStream(), "");
WriteString (tcpNewClient.GetStream(), ((AttachmentInfo)m_alAttachments[i]).Bytes); // 写入文件的内容
WriteString (tcpNewClient.GetStream(), "");
}

Command (tcpNewClient.GetStream(), ".", "250"); // 最后写完了,输入"."

// 关闭连接
tcpNewClient.Close ();
}
/// <summary>
/// 向流中写入字符
/// </summary>
/// <param name="p_netStream">来自TcpClient的流</param>
/// <param name="p_str">写入的字符</param>
protected void WriteString (NetworkStream p_netStream, string p_str)
{
p_str = p_str + "\r\n"; // 加入换行符

// 将命令行转化为byte[]
byte[] bWrite = Encoding.GetEncoding(m_strLanguageEncoding).GetBytes(p_str.ToCharArray());

// 由于每次写入的数据大小是有限制的,那么我们将每次写入的数据长度定在75个字节,一旦命令长度超过了75,就分步写入。
int iStart=0;
int iLength = bWrite.Length;
int iPage = 0;
int iSize = 75;
int iCount = iSize;
try
{
if (iLength>75)
{
// 数据分页
if ((iLength / iSize) * iSize < iLength)
iPage = iLength/iSize+1;
else
iPage=iLength/iSize;
for (int i=0;i<iPage;i++)
{
iStart=i*iSize;
if (i==iPage-1)
iCount=iLength-(i*iSize);
p_netStream.Write(bWrite,iStart,iCount);// 将数据写入到服务器上
}
}
else
p_netStream.Write(bWrite,0,bWrite.Length);
}
catch(Exception)
{
// 忽略错误
}
}

/// <summary>
/// 从流中读取字符
/// </summary>
/// <param name="p_netStream">来自TcpClient的流</param>
/// <returns>读取的字符</returns>
protected string ReadString (NetworkStream p_netStream)
{
string strSp = null;
byte[] by = new byte[1024];
int iSize = p_netStream.Read(by,0,by.Length);// 读取数据流
if (iSize > 0)
{
strSp = Encoding.Default.GetString(by);// 转化为String
}
return strSp;
}

/// <summary>
/// 发出命令并判断返回信息是否正确
/// </summary>
/// <param name="p_netStream">来自TcpClient的流</param>
/// <param name="p_strCommand">命令</param>
/// <param name="p_strState">正确的状态码</param>
/// <returns>是否正确</returns>
protected bool Command (NetworkStream p_netStream, string p_strCommand, string p_strState)
{
string strSp = null;
bool bSuccess = false;
try
{
// 写入命令
WriteString (p_netStream, p_strCommand);
strSp = ReadString (p_netStream);// 接受返回信息
if (strSp.IndexOf(p_strState) != -1)// 判断状态码是否正确
bSuccess=true;
}
catch(Exception)
{
// 忽略错误
}
return bSuccess;
}

/// <summary>
/// 字符串编码为Base64
/// </summary>
/// <param name="p_str">字符串</param>
/// <returns>Base64编码的字符串</returns>
protected string ToBase64 (string p_str)
{
try
{
byte[] by = Encoding.Default.GetBytes (p_str.ToCharArray());
p_str = Convert.ToBase64String (by);
}
catch(Exception)
{
// 忽略错误
}
return p_str;
}
/// <summary>
/// 表示一封待发送的邮件
/// </summary>
public MailSender()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#endregion

#region "Tools"
/// <summary>
/// 回复格式化html的格式到htmlt格式
/// </summary>
/// <param name="p_strOldStr">要格式化的字符串</param>
/// <param name="p_strSeparator_n"></param>
/// <param name="p_strSeparator_r"></param>
/// <returns></returns>
public string reformatSpecailHtml_toHtml(string p_strOldStr,string p_strSeparator_n,string p_strSeparator_r)
{
//string result;
while(p_strOldStr.IndexOf("<")>-1 || p_strOldStr.IndexOf("&gt")>-1 || p_strOldStr.IndexOf("@$@_n")>-1 || p_strOldStr.IndexOf("@$@_r")>-1)
{
if(p_strOldStr.IndexOf("<")>-1)
{
p_strOldStr = p_strOldStr.Substring(0,p_strOldStr.IndexOf("<")) + "<" + p_strOldStr.Substring(p_strOldStr.IndexOf("<")+4);
}
else if(p_strOldStr.IndexOf("&gt")>-1)
{
p_strOldStr = p_strOldStr.Substring(0,p_strOldStr.IndexOf("&gt")) + ">" + p_strOldStr.Substring(p_strOldStr.IndexOf("&gt")+4);
}
else if(p_strOldStr.IndexOf(p_strSeparator_n)>-1)
{
p_strOldStr = p_strOldStr.Substring(0,p_strOldStr.IndexOf(p_strSeparator_n)) + "<br>" + p_strOldStr.Substring(p_strOldStr.IndexOf(p_strSeparator_n) + p_strSeparator_n.Length);
}
else if(p_strOldStr.IndexOf(p_strSeparator_r)>-1)
{
p_strOldStr = p_strOldStr.Substring(0,p_strOldStr.IndexOf(p_strSeparator_r)) + "<br>" + p_strOldStr.Substring(p_strOldStr.IndexOf(p_strSeparator_r) + p_strSeparator_r.Length);
}
else
{
p_strOldStr = p_strOldStr;
}
}
return p_strOldStr;
}
/// <summary>
/// 格式化html的格式(目前不用)
/// </summary>
/// <param name="p_strOldStr">要格式化的字符串</param>
/// <returns></returns>
private string formatSpecailHtml(string p_strOldStr)
{
string result;
if(p_strOldStr.IndexOf("<")>-1)
{
result = p_strOldStr.Substring(0,p_strOldStr.IndexOf("<")) + "<" + p_strOldStr.Substring(p_strOldStr.IndexOf("<")+1);
formatSpecailHtml(result);
}
else if(p_strOldStr.IndexOf(">")>-1)
{
result = p_strOldStr.Substring(0,p_strOldStr.IndexOf(">")) + ">" + p_strOldStr.Substring(p_strOldStr.IndexOf(">")+1);
formatSpecailHtml(result);
}
else
{
result = p_strOldStr;
}
return result;
}
/// <summary>
/// 回复格式化html的格式到txt格式
/// </summary>
/// <param name="p_strOldStr">要格式化的字符串</param>
/// <param name="p_strSeparator_n"></param>
/// <param name="p_strSeparator_r"></param>
/// <returns></returns>
public string reformatSpecailHtml_toTxt(string p_strOldStr,string p_strSeparator_n,string p_strSeparator_r)
{
//string result;
while(p_strOldStr.IndexOf("<")>-1 || p_strOldStr.IndexOf("&gt")>-1 || p_strOldStr.IndexOf(p_strSeparator_n)>-1 || p_strOldStr.IndexOf(p_strSeparator_r)>-1)
{
if(p_strOldStr.IndexOf("<")>-1)
{
p_strOldStr = p_strOldStr.Substring(0,p_strOldStr.IndexOf("<")) + "<" + p_strOldStr.Substring(p_strOldStr.IndexOf("<")+4);
}
else if(p_strOldStr.IndexOf("&gt")>-1)
{
p_strOldStr = p_strOldStr.Substring(0,p_strOldStr.IndexOf("&gt")) + ">" + p_strOldStr.Substring(p_strOldStr.IndexOf("&gt")+4);
}
else if(p_strOldStr.IndexOf(p_strSeparator_n)>-1)
{
p_strOldStr = p_strOldStr.Substring(0,p_strOldStr.IndexOf(p_strSeparator_n)) + "\n" + p_strOldStr.Substring(p_strOldStr.IndexOf(p_strSeparator_n) + p_strSeparator_n.Length);
}
else if(p_strOldStr.IndexOf(p_strSeparator_r)>-1)
{
p_strOldStr = p_strOldStr.Substring(0,p_strOldStr.IndexOf(p_strSeparator_r)) + "\r" + p_strOldStr.Substring(p_strOldStr.IndexOf(p_strSeparator_r) + p_strSeparator_r.Length);
}
else
{
p_strOldStr = p_strOldStr;
}
}
return p_strOldStr;
}
#endregion

#region "Use"
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="p_strMailFrom">发件人地址</param>
/// <param name="p_strMailTo">收件人地址</param>
/// <param name="p_strMailFormat">邮件主体格式</param>
/// <param name="p_strMailSubject">邮件主题</param>
/// <param name="p_strMailBody">邮件主体</param>
/// <param name="p_strMailAttachmentPaths">附件路径</param>
/// <param name="mailSmtp">smtp服务地址</param>
/// <param name="smtpUser"></param>
/// <param name="p_strSmtpPassword"></param>
/// <param name="p_strSeparator_n"></param>
/// <param name="p_strSeparator_r"></param>
public void send(string p_strMailFrom,string[] p_strMailTo,string p_strMailFormat,string p_strMailSubject,string p_strMailBody,string[] p_strMailAttachmentPaths,string mailSmtp,string smtpUser,string p_strSmtpPassword,string p_strSeparator_n,string p_strSeparator_r)
{
//MailSender myEmail = null;
try
{
//myEmail = new MailSender();
this.From = p_strMailFrom;
this.To = p_strMailTo;
this.Subject = p_strMailSubject;
this.Body = reformatSpecailHtml_toTxt(p_strMailBody,p_strSeparator_n,p_strSeparator_r);
this.HtmlBody = reformatSpecailHtml_toHtml(p_strMailBody,p_strSeparator_n,p_strSeparator_r);
if(p_strMailFormat.ToUpper() == "HTML")
{
this.IsHtml = true;
}
else
{
this.IsHtml = false;
}

for(int i=0;i<p_strMailAttachmentPaths.Length;i++)
{
if(p_strMailAttachmentPaths[i] != null && p_strMailAttachmentPaths[i].Length > 0)
{
object tempObj = new MailSender.AttachmentInfo(p_strMailAttachmentPaths[i]);
this.Attachments.Add(tempObj);
}
}

this.Server = mailSmtp;
this.UserName = smtpUser;
this.Password = p_strSmtpPassword;
//this.SendMail();
SendMail();
}
catch(Exception ex)
{
throw new Exception("使用MailSender失败",ex);
}
}
/// <summary>
/// 发送邮件(使用默认分隔符号)
/// </summary>
/// <param name="p_strMailFrom">发件人地址</param>
/// <param name="p_strMailTo">收件人地址</param>
/// <param name="p_strMailFormat">邮件主体格式</param>
/// <param name="p_strMailSubject">邮件主题</param>
/// <param name="p_strMailBody">邮件主体</param>
/// <param name="p_strMailAttachmentPaths">附件路径</param>
/// <param name="mailSmtp">smtp服务地址</param>
/// <param name="smtpUser"></param>
/// <param name="p_strSmtpPassword"></param>
/// Writer:Nick
/// Create Date:2004-12-20
public void send(string p_strMailFrom,string[] p_strMailTo,string p_strMailFormat,string p_strMailSubject,string p_strMailBody,string[] p_strMailAttachmentPaths,string mailSmtp,string smtpUser,string p_strSmtpPassword)
{
string strSeparator_n = "@$@_n";
string strSeparator_r = "@$@_r";
send(p_strMailFrom,p_strMailTo,p_strMailFormat, p_strMailSubject, p_strMailBody, p_strMailAttachmentPaths, mailSmtp, smtpUser, p_strSmtpPassword,strSeparator_n,strSeparator_r);
}
/// <summary>
/// 发送邮件(无附件)
/// </summary>
/// <param name="p_strMailFrom">发件人地址</param>
/// <param name="p_strMailTo">收件人地址</param>
/// <param name="p_strMailFormat">邮件主体格式</param>
/// <param name="p_strMailSubject">邮件主题</param>
/// <param name="p_strMailBody">邮件主体</param>
/// <param name="mailSmtp">smtp服务地址</param>
/// <param name="smtpUser"></param>
/// <param name="p_strSmtpPassword"></param>
/// Writer:Nick
/// Create Date:2004-12-20
public void send(string p_strMailFrom,string[] p_strMailTo,string p_strMailFormat,string p_strMailSubject,string p_strMailBody,string mailSmtp,string smtpUser,string p_strSmtpPassword)
{
string[] strMailAttachmentPaths = new string[3];
send(p_strMailFrom,p_strMailTo,p_strMailFormat,p_strMailSubject,p_strMailBody,strMailAttachmentPaths, mailSmtp, smtpUser, p_strSmtpPassword);
}
/// <summary>
/// 发送邮件(无附件、txt格式)
/// </summary>
/// <param name="p_strMailFrom">发件人地址</param>
/// <param name="p_strMailTo">收件人地址</param>
/// <param name="p_strMailSubject">邮件主题</param>
/// <param name="p_strMailBody">邮件主体</param>
/// <param name="mailSmtp">smtp服务地址</param>
/// <param name="smtpUser"></param>
/// <param name="p_strSmtpPassword"></param>
/// Writer:Nick
/// Create Date:2004-12-20
public void send(string p_strMailFrom,string[] p_strMailTo,string p_strMailSubject,string p_strMailBody,string mailSmtp,string smtpUser,string p_strSmtpPassword)
{
string strMailFormat = "txt";
send(p_strMailFrom,p_strMailTo,strMailFormat,p_strMailSubject,p_strMailBody,mailSmtp,smtpUser,p_strSmtpPassword);
}
/// <summary>
/// 发送邮件
/// </summary>
/// Writer:Nick
/// Create Date:2004-12-20
public void send()
{
SendMail();
}
/// <summary>
/// 销毁(预留)
/// </summary>
/// Writer:Nick
/// Create Date:2004-12-20
public void Dispose()
{
}
#endregion
}
}

时间: 2024-10-29 04:29:44

改进了的一个邮件发送类的相关文章

用c#写的smtp邮件发送类

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 KS

ThinkPHP邮件发送类

最近在做一个项目,需要有邮件发送的功能,服务器邮件发送的话,服务器上必须有能链接邮件服务器,才能实现以下的步骤,现在就给大家分享一下,专门做了一个邮件的发送类 /** * 系统邮件发送函数 * @param string $to 接收邮件者邮箱 * @param string $name 接收邮件者名称 * @param string $subject 邮件主题 * @param string $body 邮件内容 * @param string $attachment 附件列表 * @retu

PHP邮件发送类

Swift Mailer 和前面介绍的PHPMailer一样,也是一个PHP邮件发送类.它不依赖于 PHP 自带的mail() 函数,因为该函数在发送多个邮件时占用的系统资源很高.Swift 直接与 SMTP 服务器通讯,具有非常高的发送速度和效率. phpmailer邮件找回密码 1.根据邮件找回链接进入重置密码操作页面 .仅一周内.一次有效 2.重置密码 (也可以将密码发送直接登录) 生成邮件找回邮件 用linux下安装的sendmail写了一个发送email的程序 Java代码   <?p

PHP实现发送邮件的方法(基于简单邮件发送类)_php技巧

本文实例讲述了PHP实现发送邮件的方法.分享给大家供大家参考,具体如下: 邮件发送类 <?php /*邮件发送类 *功能:使用smtp服务器发送邮件 */ class smtp { /* 全局变量 */ var $smtp_port; var $time_out; var $host_name; var $log_file; var $relay_host; var $debug; var $auth; var $user; var $pass; var $sock; /* 构造函数 */ fu

CI框架简单邮件发送类实例_php实例

本文实例讲述了CI框架简单邮件发送类.分享给大家供大家参考,具体如下: ci框架绝对是php初学中想要的东西,它能极大的缩短你的代码量! 下面看看我的发送邮件的简单演示: function email() { $this->load->library('email'); $config['protocol'] = 'smtp'; $config['smtp_host'] = 'smtp.163.com'; $config['smtp_user'] = 'jb51@163.com';//这里写上

CI框架简单邮件发送类实例

本文实例讲述了CI框架简单邮件发送类.分享给大家供大家参考,具体如下: ci框架绝对是php初学中想要的东西,它能极大的缩短你的代码量! 下面看看我的发送邮件的简单演示: function email() { $this->load->library('email'); $config['protocol'] = 'smtp'; $config['smtp_host'] = 'smtp.163.com'; $config['smtp_user'] = 'jb51@163.com';//这里写上

PHP在线邮件发送类,通过SMTP来发送

<?  /*  * 邮件发送类 * 作    者:多菜鸟 * 联系邮箱:kingerq AT msn DOT com * 创建时间:2005-08-19 * 注明:此类为改装过来的,忘记出处了 */class smail { //您的SMTP 服务器供应商,可以是域名或IP地址 var $smtp = "smtp.163.com";  //SMTP需要要身份验证设值为 1 不需要身份验证值为 0,现在大多数的SMTP服务商都要验证,如不清楚请与你的smtp 服务商联系. var

PHP实现支持SSL连接的SMTP邮件发送类

 这篇文章主要介绍了PHP实现支持SSL连接的SMTP邮件发送类,实例分析了php实现smtp邮件发送类的原理与技巧,以及支持SSL连接的方法,需要的朋友可以参考下     本文实例讲述了PHP实现支持SSL连接的SMTP邮件发送类.分享给大家供大家参考.具体如下: 该实例代码测试过了gmail和QQ邮箱的SMTP.具体代码如下: 代码如下: <?php /** * 邮件发送类 * 支持发送纯文本邮件和HTML格式的邮件,可以多收件人,多抄送,多秘密抄送,带附件(单个或多个附件),支持到服务器的

PHP邮件发送类PHPMailer用法实例详解

 本文实例讲述了PHP邮件发送类PHPMailer用法,并详细讲述了其具体的操作步骤.分享给大家供大家参考.具体步骤如下: 1.在服务器安装 sendmail 1 sudo apt-get install sendmail 2.启动 sendmail 1 sudo /etc/init.d/sendmail start 3.修改 php.ini 1 2 3 4 [mail function]  SMTP = localhost  smtp_port = 25  sendmail_from = me