public ActionResult Index() { /*第一种,利用Google的smtp来发送邮件*/ SmtpClient client = new SmtpClient("smtp.163.com", 25); Random Rdm = new Random(); //产生0到100的随机数 int iRdm = Rdm.Next(99999, 100000); MailMessage msg = new MailMessage("邮箱@163.com", "接收的邮箱", "验证码", iRdm.ToString()); client.UseDefaultCredentials = false; System.Net.NetworkCredential basicAuthenticationInfo = new System.Net.NetworkCredential("163邮箱注册的账号", "163邮箱注册的密码");
client.Credentials = basicAuthenticationInfo; client.EnableSsl = true; client.Send(msg); return Content("s"); }
要发送邮箱,首先要在163邮箱注册一个账号,用这个账号就可以发邮箱了。。