200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > .net 邮箱验证码 邮箱验证码实现用户注册

.net 邮箱验证码 邮箱验证码实现用户注册

时间:2024-06-27 06:42:06

相关推荐

.net 邮箱验证码 邮箱验证码实现用户注册

.net邮箱注册

前端时间做项目,手机短信验证需要购买服务,而且容易被工具.

纠结之后,用了邮箱验证.

直接上代码

/// <summary>/// 同步发送邮件/// </summary>/// <param name="to">收件人邮箱地址</param>/// <param name="subject">主题</param>/// <param name="body">内容</param>/// <param name="encoding">编码</param>/// <param name="isBodyHtml">是否Html</param>/// <param name="enableSsl">是否SSL加密连接</param>/// <returns>是否成功</returns>public static bool Send(string to, string subject, string body, string encoding = "UTF-8", bool isBodyHtml = true, bool enableSsl = false){//try//{MailMessage message = new MailMessage();// 接收人邮箱地址message.To.Add(new MailAddress(to));message.From = new MailAddress(MailUserName, MailName);message.BodyEncoding = Encoding.GetEncoding(encoding);message.Body = body;//GB2312message.SubjectEncoding = Encoding.GetEncoding(encoding);message.Subject = subject;message.IsBodyHtml = isBodyHtml;SmtpClient smtpclient = new SmtpClient(MailServer, 587);smtpclient.Credentials = new workCredential(MailUserName, MailPassword);//SSL连接smtpclient.EnableSsl = enableSsl;smtpclient.Send(message);return true;//}//catch (Exception ex)//{// Console.WriteLine(ex.ToString());// return false;//}}

[HttpPost][ValidateAntiForgeryToken][AjaxOnly]public ActionResult SendEmail(VerificationEntity entity){VerificationEntity model = new VerificationEntity();if (entity.Telphone.IsEmpty())return Info("请输入正确邮箱地址");//if (entity.CodeType == 3)//{// var Cmodel = cuserBll.CheckCUser(entity.Telphone);// if(Cmodel==null)// return Info("账号不存在,输入正确的账号!");//}model.Telphone = entity.Telphone;model.CodeType = entity.CodeType;model.Type = 1;string ret = verificationBLL.AddCode(model);if (ret == ""){try{bool flag = false;if (model.CodeType == 1)flag = MailHelper.Send(entity.Telphone, "28找群注册验证码通知", "注册验证码:" + model.Content + " 30分钟内有效,请输入验证码,完成注册<br> 资源不断,人脉无线", "UTF-8", true, true);else if (model.CodeType == 3)flag = MailHelper.Send(entity.Telphone, "28找群密码找回验证码通知", "密码找回验证码:" + model.Content + " 30分钟内有效,请输入验证码,完成操作<br> 资源不断,人脉无线", "UTF-8", true, true);if (!flag)return Error("邮件发送失败,请检查邮箱地址是否正确");}catch (Exception ex){//return Error(ex.Message);throw;}return Success("验证码已经发送,请进入邮箱查看验证码。");}elsereturn Error(ret);}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。