在做注册的时候博主遇到了个很坑爹的问题
那就是本地发送邮件正常可是搬运到阿里云服务器发送邮件就gg了查询了很久才知道阿里云默认是把25发送邮件端口给封了
也就是说放在阿里云服务器的发送邮件是无法以无ssl加密的方式发送的,必须通过ssl家里的465端口去发送邮件
然后我们调用封装好Mail类
Mail类下载地址:下载地址
发送邮件格式如下:
string title = "博客账号激活";string MailContent = "您好,感谢您在我的博客注册帐户!激活帐户需要点击下面的链接:" + xxxx + "";Boolean r = Mail.WebSendEmail("发送给的邮箱号", "", title, MailContent);
当然在注册注册链接中需要一些字段我就没贴出来了,字段就在注册的时候生成的然后插入数据库,在他访问的时候去数据库取值判断字段值是否相同和时间是否过期,如果正确就给予账号激活,大致思路就是这样实际代码我就不贴出来了
当然在使用tx邮箱发送邮件的时候也需要注意一个问题那就是tx以前发送邮件的密码是独立密码现在改为授权码了,授权码在开启stmp的下面
全部的注册代码如下(部分数据链接不方便展示删除了):
#region 注册//注册[ErrorHandler]public ActionResult Register(Entity.Member memeber, string vercode, string rePassword){Entity.Alert alert = new Entity.Alert();if (IsPost){string validateCode = Session["ValidateCode"].ToString();if (memeber.Password.Length<6||memeber.Password.Length>16){alert.status = 1;alert.msg = "密码长度应该为6-16位";return Json(alert, JsonRequestBehavior.AllowGet);}if (memeber.Password != rePassword){alert.status = 1;alert.msg = "两次密码不一致";return Json(alert, JsonRequestBehavior.AllowGet);}else{if (vercode != validateCode){alert.status = 1;alert.msg = "人类验证失败";return Json(alert, JsonRequestBehavior.AllowGet);}else{Entity.Member getEmail = Entity.Helper.Member.GetMemberByEmail(memeber.Email);if (getEmail != null){alert.status = 1;alert.msg = "该邮箱已经注册";return Json(alert, JsonRequestBehavior.AllowGet);}else{string Code = Entity.Helper.Common.GenerateCheckCode(12);memeber.Password = memeber.Password.Encrypt();memeber.Power = "1";memeber.State = "0";memeber.Sex = "0";memeber.Img = "/attached/2017/11/231552029959.jpg";memeber.Describe = "这个人很懒还未设置签名";memeber.ZcTime = DateTime.Now;memeber.Code = Code;Entity.Helper.Member.Register(memeber);try{Entity.Member ActiveMail = Entity.Helper.Member.GetMemberByEmail(memeber.Email);xsw.Framework.Config.FrameworkConfig config =xsw.Framework.Config.FrameworkConfig.Instance<xsw.Framework.Config.FrameworkConfig>();string title = "博客账号激活";string MailContent = "您好,感谢您在我的博客注册帐户!激活帐户需要点击下面的链接:";Boolean r = Mail.WebSendEmail(memeber.Email, "", title, MailContent);Entity.SiteMessages message = new SiteMessages();message.Content = "欢迎注册博客;message.SendUserID="1";message.UserID=ActiveMail.MemberID.ToString();message.IsView=false;message.Title="欢迎";message.CreateDate=DateTime.Now;DBSession.TryGet().Insert<SiteMessages>(message);}catch (Exception e){alert.status = 1;alert.msg = "注册成功,但激活邮件发送失败";}alert.action = "Login";alert.status = 0;alert.msg = "注册成功";return Json(alert, JsonRequestBehavior.AllowGet);}}}}return ManageView();}