.net发送邮件
来源:互联网 发布:正能量的网络流行词汇 编辑:程序博客网 时间:2024/05/16 17:57
主要代码如下:
using System.Net.Sockets;
using System.Web.Mail;
發送郵件#region 發送郵件
private void btnSendOrder_ServerClick(object sender, System.EventArgs e)
...{
SendOrderMesageMail();
}
#endregion
*************發送郵件*************************#region *************發送郵件*************************
/**//// <summary>
/// 发送email
/// </summary>
/// <param name="SendEMail">發送郵箱地址</param>
/// <param name="StrBody">郵件內容</param>
/// <param name="StrTitle">郵件主題</param>
private void SendEmail(string sendEmail, string body, string title)
...{
MailAttachment mail = null;
MailMessage myMail = new MailMessage();
try
...{
string strSubject = title;//邮件主题
string strFrom = ConfigurationSettings.AppSettings["ServiceMail"].ToString(); //電子郵件的發信人地址
string strhost = SqlConfig.MailServer; //smtp事務的主機的名稱或IP地址
string strBody = body; //電子郵件的正文
myMail.From = strFrom;
myMail.To=sendEmail;
myMail.Subject = strSubject;
myMail.Priority = MailPriority.Low;
myMail.Body = strBody;
myMail.BodyFormat =System.Web.Mail.MailFormat.Html;
myMail.Priority = MailPriority.High;
SmtpMail.SmtpServer.Insert(0,SqlConfig.MailServer);
SmtpMail.Send(myMail);
mail = null;
}
catch (Exception exc)
...{
mail = null;
this.Response.Write("<script type ='text/javascript' >alert('郵件發送失敗!')</script>");
}
}
/**//// <summary>
/// 向用戶發送建議價格
/// </summary>
private void SendOrderMesageMail()
...{
string email = "benxiangyanzi@163.com";
string strTitle1 = "[yam天空網站]—對帳通知信"; //郵件標題
string imgUrl = SqlConfig.UploadFile;
string strContent = GetEmailBody(Server.MapPath("../Order/SendOrderEmail.txt"));
strContent = strContent.Replace("[ImgUrl]", imgUrl).Replace("[Messgae]",html).Replace("[EndTime]",EndTime).Replace("[BeginTime]",BeginTime).Replace("[Count]",OrderCount).Replace("[Price]",Price).Replace("[ShouPrice]",SPrice).Replace(" ","");
Price="";
SPrice="";
OrderCount="";
BeginTime="";
EndTime="";
html="";
SendEmail(email, strContent, strTitle1);
}
/**//// <summary>
/// 取郵件內容
/// </summary>
/// <param name="MailTxtName"></param>
/// <returns></returns>
private string GetEmailBody(string mailTxtName)
...{
StreamReader sr = File.OpenText(mailTxtName);
mailTxtName = sr.ReadToEnd();
sr.Close();
sr = null;
return mailTxtName;
}
#endregion
using System.Web.Mail;
發送郵件#region 發送郵件
private void btnSendOrder_ServerClick(object sender, System.EventArgs e)
...{
SendOrderMesageMail();
}
#endregion
*************發送郵件*************************#region *************發送郵件*************************
/**//// <summary>
/// 发送email
/// </summary>
/// <param name="SendEMail">發送郵箱地址</param>
/// <param name="StrBody">郵件內容</param>
/// <param name="StrTitle">郵件主題</param>
private void SendEmail(string sendEmail, string body, string title)
...{
MailAttachment mail = null;
MailMessage myMail = new MailMessage();
try
...{
string strSubject = title;//邮件主题
string strFrom = ConfigurationSettings.AppSettings["ServiceMail"].ToString(); //電子郵件的發信人地址
string strhost = SqlConfig.MailServer; //smtp事務的主機的名稱或IP地址
string strBody = body; //電子郵件的正文
myMail.From = strFrom;
myMail.To=sendEmail;
myMail.Subject = strSubject;
myMail.Priority = MailPriority.Low;
myMail.Body = strBody;
myMail.BodyFormat =System.Web.Mail.MailFormat.Html;
myMail.Priority = MailPriority.High;
SmtpMail.SmtpServer.Insert(0,SqlConfig.MailServer);
SmtpMail.Send(myMail);
mail = null;
}
catch (Exception exc)
...{
mail = null;
this.Response.Write("<script type ='text/javascript' >alert('郵件發送失敗!')</script>");
}
}
/**//// <summary>
/// 向用戶發送建議價格
/// </summary>
private void SendOrderMesageMail()
...{
string email = "benxiangyanzi@163.com";
string strTitle1 = "[yam天空網站]—對帳通知信"; //郵件標題
string imgUrl = SqlConfig.UploadFile;
string strContent = GetEmailBody(Server.MapPath("../Order/SendOrderEmail.txt"));
strContent = strContent.Replace("[ImgUrl]", imgUrl).Replace("[Messgae]",html).Replace("[EndTime]",EndTime).Replace("[BeginTime]",BeginTime).Replace("[Count]",OrderCount).Replace("[Price]",Price).Replace("[ShouPrice]",SPrice).Replace(" ","");
Price="";
SPrice="";
OrderCount="";
BeginTime="";
EndTime="";
html="";
SendEmail(email, strContent, strTitle1);
}
/**//// <summary>
/// 取郵件內容
/// </summary>
/// <param name="MailTxtName"></param>
/// <returns></returns>
private string GetEmailBody(string mailTxtName)
...{
StreamReader sr = File.OpenText(mailTxtName);
mailTxtName = sr.ReadToEnd();
sr.Close();
sr = null;
return mailTxtName;
}
#endregion
txt:
<html>
<head>
<title>對帳通知</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<link rel="stylesheet" href="[MapUrl]/Css/fonts.css" type="text/css">
</head>
<body bgcolor="#f5f4f3" text="#000000" leftmargin="0" topmargin="10" marginwidth="0" marginheight="0">
<table border="0" cellspacing="0" cellpadding="0" width="1000" align="center">
<tr>
<td bgcolor="#ffffff" height="350" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="97%" class="mainbg">
<div class="white2">信件主旨:[yam天空網站] [EndTime]~[BeginTime] 對帳通知</div>
</td>
</tr>
</table>
<span class="gray" align="center"><hr noshade size="1"><br>
※此郵件為系統自動傳送,請勿直接回覆此郵件。<br>**************************************************************<br>
</span>
<p class="gray">
<span class="gray"> 親愛的捷元股份有限公司,您好:</span></p>
<p class="gray">[EndTime]~[BeginTime]| [yam天空網站]對帳資料如下表,敬請於近日開立發票請款。!<br>
</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>[Messgae]</td>
</tr>
<tr>
<td>
本期應付款共[Count]筆,貨款金額$[Price],收入金額$[ShouPrice]
</td>
</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="1" cellpadding="1" class="gray">
<tr>
<td width="24%" bgcolor="#FFFFFF"><div align="center"><img src="[ImgUrl]/Images/Store_Logo.jpg"></div></td>
<td width="69%">
<font color="#396BA8">天空傳媒股份有限公司</font></a><font color="#666666"><br>
</font> 10574台北巿民生東路133號13樓<br>
客服電話:02-25151181 </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<head>
<title>對帳通知</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<link rel="stylesheet" href="[MapUrl]/Css/fonts.css" type="text/css">
</head>
<body bgcolor="#f5f4f3" text="#000000" leftmargin="0" topmargin="10" marginwidth="0" marginheight="0">
<table border="0" cellspacing="0" cellpadding="0" width="1000" align="center">
<tr>
<td bgcolor="#ffffff" height="350" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="97%" class="mainbg">
<div class="white2">信件主旨:[yam天空網站] [EndTime]~[BeginTime] 對帳通知</div>
</td>
</tr>
</table>
<span class="gray" align="center"><hr noshade size="1"><br>
※此郵件為系統自動傳送,請勿直接回覆此郵件。<br>**************************************************************<br>
</span>
<p class="gray">
<span class="gray"> 親愛的捷元股份有限公司,您好:</span></p>
<p class="gray">[EndTime]~[BeginTime]| [yam天空網站]對帳資料如下表,敬請於近日開立發票請款。!<br>
</p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>[Messgae]</td>
</tr>
<tr>
<td>
本期應付款共[Count]筆,貨款金額$[Price],收入金額$[ShouPrice]
</td>
</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="1" cellpadding="1" class="gray">
<tr>
<td width="24%" bgcolor="#FFFFFF"><div align="center"><img src="[ImgUrl]/Images/Store_Logo.jpg"></div></td>
<td width="69%">
<font color="#396BA8">天空傳媒股份有限公司</font></a><font color="#666666"><br>
</font> 10574台北巿民生東路133號13樓<br>
客服電話:02-25151181 </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
- 使用.NET发送邮件
- 使用.NET发送邮件
- 使用.NET发送邮件
- 使用.NET发送邮件
- .net发送接收邮件
- 使用.NET发送邮件
- asp.net发送邮件
- ASP.NET发送邮件
- .NET下发送邮件
- asp.net发送邮件
- .net 2.0 邮件发送
- .net中发送邮件
- c#.net发送邮件
- .Net 发送邮件
- .net发送邮件
- NET 邮件发送
- .NET邮件发送
- 使用.NET发送邮件
- 您没有对CONFIG文件夹访问权限,详情参见安装文档
- 谁来救救我的家
- 地震了,学计算机的,能做什么?
- 如何C#中实现在TreeView查找某一节点
- AOP面向切面的理解
- .net发送邮件
- 关于DataList使用DropDownList的分页实现 技巧实例源码
- 无弹出框的验证
- 有人问“AppSettings和ConnectionStrings的区别”?
- 我的工作
- 利用struts框架实现URL地址映射配置的关键点
- How to: Convert System::String to wchar_t* or char*
- 什么是串口
- ADO.NET的最佳实践技巧