System.Net.Mail 发送邮件示例
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Web;
5using System.Web.UI;
6using System.Web.UI.WebControls;
7using System.Net.Mail;
8using System.Net;
9public partial class attract_ok : System.Web.UI.Page
10{
11 protected void Page_Load(object sender, EventArgs e)
12 {
13 if (!Page.IsPostBack)
14 {
15 Dictionary<string, string> userInfo = new Dictionary<string, string>();
16 userInfo.Add("姓名", Request.Form["JName"]);
17 userInfo.Add("性别", Request.Form["JSexX"]);
18 userInfo.Add("年龄", Request.Form["JAge"]);
19 userInfo.Add("学历", Request.Form["JStud"]);
20 userInfo.Add("电话", Request.QueryString["jTel"]);
21 userInfo.Add("手机", Request.Form["jHand"]);
22 userInfo.Add("地址", Request.Form["jAddr"]);
23 userInfo.Add("邮件", Request.Form["jEmail"]);
24 userInfo.Add("公司名称", Request.Form["jCompany"]);
25 userInfo.Add("地区", Request.Form["JArea"]);
26 userInfo.Add("公司介绍", Request.Form["JIntro"]);
27 userInfo.Add("培训计划", Request.Form["JPlan"]);
28 System.Text.StringBuilder sb = new System.Text.StringBuilder();
29 foreach (KeyValuePair<string,string> si in userInfo) //Dictionary<Tkey,TValue>迭代
30 {
31 sb.Append(si.Key + ":" + si.Value + "<br />");
32 }
33 using (MailMessage ms = new MailMessage("q12177@126.com", "44324814@qq.com,love1800@gmail.com")) //发送邮件地址应该同下面验证的用户是同一个用户
34 {
35 ms.Subject = "信息! http://www.rsion.com/";
36 ms.Body ="该邮件发送日期:"+DateTime.Now.ToString()+"<br/><br/>信息如下:<br/>"+sb.ToString();
37 ms.IsBodyHtml = true;
38 SmtpClient sc = new SmtpClient("smtp.126.com");//发送邮件地址
39 sc.UseDefaultCredentials = true; //默认验证
40 sc.Credentials = new System.Net.NetworkCredential("q12177", "1565646");//用户密码
41 try
42 {
43 sc.Send(ms);
44 }
45 catch { Response.Write("对不起发送失败!邮件服务器验证失败引起的,请联系QQ:959398298"); }
46 }
48 }
49 }
50}
51
2using System.Collections;
3using System.Collections.Generic;
4using System.Web;
5using System.Web.UI;
6using System.Web.UI.WebControls;
7using System.Net.Mail;
8using System.Net;
9public partial class attract_ok : System.Web.UI.Page
10{
11 protected void Page_Load(object sender, EventArgs e)
12 {
13 if (!Page.IsPostBack)
14 {
15 Dictionary<string, string> userInfo = new Dictionary<string, string>();
16 userInfo.Add("姓名", Request.Form["JName"]);
17 userInfo.Add("性别", Request.Form["JSexX"]);
18 userInfo.Add("年龄", Request.Form["JAge"]);
19 userInfo.Add("学历", Request.Form["JStud"]);
20 userInfo.Add("电话", Request.QueryString["jTel"]);
21 userInfo.Add("手机", Request.Form["jHand"]);
22 userInfo.Add("地址", Request.Form["jAddr"]);
23 userInfo.Add("邮件", Request.Form["jEmail"]);
24 userInfo.Add("公司名称", Request.Form["jCompany"]);
25 userInfo.Add("地区", Request.Form["JArea"]);
26 userInfo.Add("公司介绍", Request.Form["JIntro"]);
27 userInfo.Add("培训计划", Request.Form["JPlan"]);
28 System.Text.StringBuilder sb = new System.Text.StringBuilder();
29 foreach (KeyValuePair<string,string> si in userInfo) //Dictionary<Tkey,TValue>迭代
30 {
31 sb.Append(si.Key + ":" + si.Value + "<br />");
32 }
33 using (MailMessage ms = new MailMessage("q12177@126.com", "44324814@qq.com,love1800@gmail.com")) //发送邮件地址应该同下面验证的用户是同一个用户
34 {
35 ms.Subject = "信息! http://www.rsion.com/";
36 ms.Body ="该邮件发送日期:"+DateTime.Now.ToString()+"<br/><br/>信息如下:<br/>"+sb.ToString();
37 ms.IsBodyHtml = true;
38 SmtpClient sc = new SmtpClient("smtp.126.com");//发送邮件地址
39 sc.UseDefaultCredentials = true; //默认验证
40 sc.Credentials = new System.Net.NetworkCredential("q12177", "1565646");//用户密码
41 try
42 {
43 sc.Send(ms);
44 }
45 catch { Response.Write("对不起发送失败!邮件服务器验证失败引起的,请联系QQ:959398298"); }
46 }
48 }
49 }
50}
51
原创内容请您保留出处及地址 , 主页:展益