Member 是数据实体,穿过来的也就是当前注册用户的信息. 存储的数据一定要有邮箱信息
private void SendAuthCodeToMember(Member member)
{
string mailBody = System.IO.File.ReadAllText(Server.MapPath("~/MemberRegisterEMailTemplate.html")); //发送的内容网址
mailBody = mailBody.Replace("{{Name}}",member.Name);//用户名及是邮箱->发送的目标
mailBody = mailBody.Replace("{{RegisterOn}}", member.RegisterOn.ToString("F"));
var auth_url = new UriBuilder(Request.Url)
{
Path = Url.Action("ValidateRegister",new { id=member.AuthCode}), //ValidateRegister 点击激活链接时返回的方法,(自定义,一般是要自己在去数据库取回来数据进行对比然后激活成功!)
Query=""
};
mailBody = mailBody.Replace("{{AUTH_URL}}", auth_url.ToString());
try {
//SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
SmtpClient SmtpServer = new SmtpClient()
{
Host = "smtp.163.com",
UseDefaultCredentials = true,
DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential("***@163.com", "密码***")//代理发送的网易账户
//EnableSsl = true
};
MailMessage mail = new MailMessage()
{
From = new MailAddress("***@163.com")//代理发送的网易账户
};
mail.To.Add(member.Email);
mail.Subject = "会员注册确认信";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.Body = mailBody;
mail.Priority = System.Net.Mail.MailPriority.High;
mail.IsBodyHtml = true ;
SmtpServer.Send(mail);
}
catch(Exception ex) {
throw ex;
}
}
MemberRegisterEMailTemplate.html 大概这样的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>会员注册确认信</h1>
<p>亲爱的{{Name}}你好:</p>
<p>
由于您在{{RegisterOn}}注册成为本站会员,为了完成会员注册程序,我们请您点击
一下链接用以确认你的Email地址是有效的:
<br/>
<a href="{{AUTH_URL}}" target="_blank">{{AUTH_URL}}</a>
</p>
<a>谢谢</a>
<p></p>
</body>
</html>