天天看点

Asp.net(c#)发送电子邮件

using System.web.Mail;?

??????????? MailMessage msg = new MailMessage();

??????????? //?????瑰?板??(濡?[email?protected])

??????????? msg.From = "[email?protected]";

??????????? //?ユ?舵?瑰?板??(濡?[email?protected])

??????????? msg.To = "[email?protected]";

??????????? //姝f????瀹圭被??

??????????? msg.BodyFormat = MailFormat.Html;

??????????? //姝f????瀹圭???

??????????? msg.BodyEncoding = System.Text.Encoding.Default;

??????????? //涓婚?

??????????? msg.Subject = "寮?澶у?????ㄩ??濂?;

??????????? //??瀹?

??????????? msg.Body = "<html><head><META content=zh-cn http-equiv=Content-Language><meta http-equiv='Content-Type' content='text/html; charset=gb2312'><style type=text/css>A:link { FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #000000}A:visited {FONT-SIZE: 9pt; TEXT-DECORATION: none; color: #666666}A:hover {COLOR: #ff6600; FONT-SIZE: 9pt; TEXT-DECORATION: underline}BODY {FONT-SIZE: 9pt} --></style></head><body><font color=red>?ㄦ?峰??锛?" + UserName.Text.Trim() + "</font><br><font color=green>瀵???锛?" + strUserPsw.ToString() + "</font><br><b>楠?璇??板??锛?</b><a href='http://192.168.1.98/AllFiles/Member/CheckFromEmail.aspx?UserName=" + UserName.Text.Trim() + "'target=_blank>http://192.168.1.98/AllFiles/Member/CheckFromEmail.aspx?UserName=" + UserName.Text.Trim() + "</a>??濡????ㄤ??界?瑰?婚?炬?ヨ?琛?璺宠浆锛?璇锋??杩?涓??板??绮?璐村?版?瑙??ㄧ???板?????存?ヨ?块????<br><font color=red>姝ら??浠朵?蹇???澶?锛?璋㈣阿??</font></body></html>";

??????????? //璁剧疆涓洪??瑕??ㄦ?烽??璇?

??????????? msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");

??????????? //璁剧疆楠?璇??ㄦ?峰??

??????????? msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "zdyguilong");

??????????? //璁剧疆楠?璇?瀵???

??????????? msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456");

??????????? //??浠舵???″?ㄥ?板??(濡?smtp.163.com)

??????????? SmtpMail.SmtpServer = "smtp.163.com";

??????????? //????

??????????? SmtpMail.Send(msg);

??????????? //Response.Write("<script language='javascript'>alert('娉ㄥ??????');window.location='../default.aspx'</script>");?

继续阅读