- public ActionResult SendEmial()
- {
- int customerID= 1;
- string validataCode = System.Guid.NewGuid().ToString();
- try {
- System.Net.Mail.MailAddress from = new System.Net.Mail.MailAddress([email protected], "wode"); //填写电子邮件地址,和显示名称
- System.Net.Mail.MailAddress to = new System.Net.Mail.MailAddress([email protected], "nide"); //填写邮件的收件人地址和名称
- //设置好发送地址,和接收地址,接收地址可以是多个
- System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
- mail.From = from;
- mail.To.Add(to);
- mail.Subject = "主题内容";
- System.Text.StringBuilder strBody = new System.Text.StringBuilder();
- strBody.Append("点击下面链接激活账号,48小时生效,否则重新注册账号,链接只能使用一次,请尽快激活!");
- strBody.Append("点击这里");
- mail.Body = strBody.ToString();
- mail.IsBodyhtml = true;//设置显示htmls
- //设置好发送邮件服务地址
- System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
- client.Host = "smtp.163.com";
- //填写服务器地址相关的用户名和密码信息
- client.Credentials = new System.Net.NetworkCredential("[email protected]", "xxxxxx");
- //发送邮件
- client.Send(mail);
- }
- catch {}
- return new EmptyResult();
- }
说明:
3. 验证码是否有效分为两种情况:1. 验证是否在规定时间内,激活链接;2. 验证码和数据库中保存的是否相同
来源: http://www.bubuko.com/infodetail-2065939.html