using System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Net.Mail;
using
System.Text;
using
System.Net;
///
///
SendMail 的摘要说明
///
public
class SendMail
{
///
/// 发送邮件方法
///
/// 接收邮件的邮箱
/// 1:审核通过 2:审核不通过 3:找回密码
///
public bool
SendMessage(string toEmail, string shValue, string loginid)
{
try
{
string title =
string.Empty;
string
emailContent = string.Empty;
string ServerPaths
=
System.Configuration.ConfigurationManager.AppSettings["ServerPath"].ToString();//本机IP
switch (shValue)
{
#region
case
"1":
title = "某网站注册审核结果--审核通过";
emailContent =
GetSucessInfo(loginid);
break;
#endregion
case
"2":
title = "某网站注册审核结果--审核未通过";
emailContent =
GetFiledInfo(loginid);
break;
case
"3":
title = "找回密码";
emailContent =
getFindPassContent(loginid, toEmail, ServerPaths);
break;
case
"4":
title = "某网站注册邮箱激活账号";
emailContent =
ActiveAccount(loginid, toEmail, ServerPaths);
break;
default:
break;
}
string smtpServer
=
System.Configuration.ConfigurationManager.AppSettings["smtpServer"].ToString();
string user =
System.Configuration.ConfigurationManager.AppSettings["MailDisplayName"].ToString();
string fromEmail =
System.Configuration.ConfigurationManager.AppSettings["MainId"].ToString();
string password =
System.Configuration.ConfigurationManager.AppSettings["MainPwd"].ToString();
SmtpClient smtp =
new SmtpClient(); //实例化一个SmtpClient
smtp.DeliveryMethod
= SmtpDeliveryMethod.Network; //将smtp的出站方式设为 Network
smtp.EnableSsl =
false;//smtp服务器是否启用SSL加密
smtp.Host =
smtpServer;//指定 smtp 服务器
smtp.Credentials =
new NetworkCredential(fromEmail, password);
MailMessage mm =
new MailMessage(); //实例化一个邮件类
mm.Priority =
MailPriority.High; //邮件的优先级,分为 Low, Normal, High,通常用 Normal即可
mm.From = new
MailAddress(fromEmail, user, Encoding.GetEncoding(936));
mm.CC.Add(new
MailAddress(toEmail, "", Encoding.GetEncoding(936)));
mm.Subject =
title; //邮件标题
mm.SubjectEncoding
= Encoding.GetEncoding(936);
mm.IsBodyHtml =
true; //邮件正文是否是HTML格式mm.BodyEncoding =
Encoding.GetEncoding(936);
mm.Body =
emailContent;
smtp.Send(mm);
return true;
}
catch
{
return false;
}
}
///
/// 发送邮件方法
///
/// 接收邮件的邮箱
/// 1:审核通过 2:审核不通过 3:找回密码
///
public bool
SendMessage(string toEmail, string shValue, string loginid,string item_list)
{
try
{
string title =
string.Empty;
string
emailContent = string.Empty;
string ServerPaths
=
System.Configuration.ConfigurationManager.AppSettings["ServerPath"].ToString();//本机IP
switch (shValue)
{
case
"5":
title = "某网站报名成功邮件提醒";
emailContent =
SuccessNotice(loginid, toEmail, ServerPaths, item_list);
break;
default:
break;
}
string smtpServer
=
System.Configuration.ConfigurationManager.AppSettings["smtpServer"].ToString();
string user =
System.Configuration.ConfigurationManager.AppSettings["MailDisplayName"].ToString();
string fromEmail =
System.Configuration.ConfigurationManager.AppSettings["MainId"].ToString();
string password =
System.Configuration.ConfigurationManager.AppSettings["MainPwd"].ToString();
SmtpClient
smtp = new SmtpClient(); //实例化一个SmtpClient
smtp.DeliveryMethod
= SmtpDeliveryMethod.Network; //将smtp的出站方式设为 Network
smtp.EnableSsl =
false;//smtp服务器是否启用SSL加密
smtp.Host =
smtpServer;//指定 smtp 服务器
smtp.Credentials =
new NetworkCredential(fromEmail, password);
MailMessage mm =
new MailMessage(); //实例化一个邮件类
mm.Priority =
MailPriority.High; //邮件的优先级,分为 Low, Normal, High,通常用 Normal即可
mm.From = new
MailAddress(fromEmail, user, Encoding.GetEncoding(936));
mm.CC.Add(new
MailAddress(toEmail, "", Encoding.GetEncoding(936)));
mm.Subject =
title; //邮件标题
mm.SubjectEncoding
= Encoding.GetEncoding(936);
mm.IsBodyHtml =
true; //邮件正文是否是HTML格式mm.BodyEncoding =
Encoding.GetEncoding(936);
mm.Body =
emailContent;
smtp.Send(mm);
return true;
}
catch
{
return false;
}
}
#region #某网站报名成功邮件提醒
///
/// 某网站报名成功邮件提醒
///
///
string
SuccessNotice(string loginid, string mail, string ServerPaths, string
item_list)
{
StringBuilder
sbContent = new StringBuilder();
sbContent.Append("
//if (1 ==1
//{
// ServerPaths =
"http://localhost:7562/PPT_Htmlweb/jftz/";
//}
sbContent.Append("
");
sbContent.Append("
");
DataTable dt_l =
DB.GetCommandDataTable("SELECT * from tb_laboratory where 1=1 and
id=" + loginid + "");
string labname =
"";
if
(dt_l!=null&&dt_l.Rows.Count>0)
{
labname =
dt_l.Rows[0]["Names"].ToString();
}
DataTable dt_yj =
DB.GetCommandDataTable("select * from tb_jftz where 1=1");
if
(dt_yj!=null&&dt_yj.Rows.Count>0)
{
sbContent.Append(dt_yj.Rows[0]["A1"].ToString()+":
" + labname + "
");
sbContent.Append("
");
sbContent.Append(" "+dt_yj.Rows[0]["A2"].ToString()+":
");
int Amount_Price =
0;
string[] itemlist
= item_list.Split(new char[] { ',' });
if
(item_list.Length > 0)
{
for (int i = 0; i
< itemlist.Length; i++)
{
DataTable dt_item
= DB.GetCommandDataTable("select * from tb_item where 1=1 and id = "
+ itemlist[i].ToString() + "");
if (dt_item !=
null && dt_item.Rows.Count > 0)
{
string code =
dt_item.Rows[0]["code"].ToString();
sbContent.Append("
" + code +
" " +
dt_item.Rows[0]["MouldName"].ToString() + "(" +
dt_item.Rows[0]["Price"].ToString() + "元)
");
Amount_Price +=
Convert.ToInt32(dt_item.Rows[0]["Price"].ToString());
}
}
}
sbContent.Append("
"+dt_yj.Rows[0]["A3"].ToString()+":" + Amount_Price + " 元
");
sbContent.Append("
");
sbContent.Append(dt_yj.Rows[0]["A4"].ToString()
+ ":
");
sbContent.Append(dt_yj.Rows[0]["A5"].ToString()
+ ":sbContent.Append(dt_yj.Rows[0]["A7"].ToString()
+ ":sbContent.Append(dt_yj.Rows[0]["A9"].ToString()
+ ":sbContent.Append(dt_yj.Rows[0]["A11"].ToString()
+ ":sbContent.Append(dt_yj.Rows[0]["A13"].ToString()
+ ":sbContent.Append("
sbContent.Append("
");
sbContent.Append("某网站
");
sbContent.Append("
");
sbContent.Append(DateTime.Now.ToString("yyyy
年 MM 月 dd 日"));
sbContent.Append("
");
sbContent.Append("注:
" +
dt_yj.Rows[0]["A15"].ToString() + "
");
sbContent.Append("
");
sbContent.Append("");
sbContent.Append(getInfo());
}
return
sbContent.ToString();
}
#endregion
#region 获取找回密码的内容
///
/// 获取找回密码的内容
///
///
string
getFindPassContent(string loginid, string mail, string ServerPaths)
{
StringBuilder
sbContent = new StringBuilder();
sbContent.Append("尊敬的某网站注册用户:");
sbContent.Append("要为您的帐户启动密码重设过程请点击以下链接:");
string urls
= UrlManage.Encrypt("&LoginID=" + loginid +
"&maile=" + mail);
sbContent.Append(""
+ ServerPaths + "/resetpwdt.aspx?1=1" + urls + "");//
sbContent.Append("");
sbContent.Append(getInfo());
return
sbContent.ToString();
}
#endregion
#region 邮箱激活账号
///
/// 邮箱激活账号
///
///
string
ActiveAccount(string loginid, string mail, string ServerPaths)
{
StringBuilder
sbContent = new StringBuilder();
sbContent.Append("尊敬的某网站注册用户:");
sbContent.Append("要为您的注册的帐户激活请点击以下链接:");
string urls =
UrlManage.Encrypt("&LoginID=" + loginid + "&maile="
+ mail);
sbContent.Append(""
+ ServerPaths + "/UserLogin.aspx?1=1" + urls + "");//
sbContent.Append("");
sbContent.Append(getInfo());
return
sbContent.ToString();
}
#endregion
string getInfo()
{
StringBuilder
sbContent = new StringBuilder();
sbContent.Append("谢谢支持!\n");
return
sbContent.ToString();
}
string
GetSucessInfo(string con)
{
StringBuilder
sbContent = new StringBuilder();
sbContent.Append("
尊敬的某网站注册用户:
您好!恭喜您在某网站注册账号被审核通过!
你可以点击链接万维网www.visa158.com登陆,进行相关操作。
" + con
+ "
谢谢您的支持!
请注意,该电子邮件地址不能接受回复邮件。更多信息请访问我们的帮助中心,网址为:http:192.168.1.102
");
return
sbContent.ToString();
}
string
GetFiledInfo(string con)
{
StringBuilder
sbContent = new StringBuilder();
sbContent.Append("
尊敬的某网站注册用户:
您好!很遗憾,您在某网站注册账号没有被审核通过!
具体原因如下:
" + con
+ "
谢谢您的支持!
请注意,该电子邮件地址不能接受回复邮件。更多信息请访问我们的帮助中心,网址为:http:192.168.1.102
");
return
sbContent.ToString();
}
}
注意:此功能需要添加一个SessionManage.dll,这个在网上可以down。
联系客服