public IHttpActionResult SendCode([FromBody] RequestModel req) { try { var parameters = Common.AesDecryp.GetAesDecryp(req.data, req.secret); var mobile = parameters["Mobile"]; using (dbDataContext db = new dbDataContext()) { var strCode = GetCode(); //验证码 var mailService = new Mafly.Mail.Mail(); //发送邮件 mailService.Send("sss1345156413" + "@qq.com", "衡水商机", "验证码", "<h2>" + strCode + "</h2>"); var code = new VCode(); code.Mobile = mobile; code.Code = strCode; code.AddTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); code.Flag = false; db.VCode.InsertOnSubmit(code); db.SubmitChanges(); return(Json(new { msg = "发送成功", state = 1 })); } } catch (Exception ex) { throw new Exception("发送失败,请稍后重试"); } }
public ActionResult Register(RegisterViewModel model) { Random random = new Random(); //如果验证码为空,发送验证码邮件 if (string.IsNullOrEmpty(model.VerificationCode)) { string VC = (random.Next(111111, 999999)).ToString(); var mailService = new Mafly.Mail.Mail(); //参数:接收者邮箱、内容 mailService.Send(model.Email, "验证码是:" + VC); modelTest = model; return(View("VerificationCodeView")); } else { // if (ModelState.IsValid) //{ var person = new Person() { FirstName = modelTest.FullName.Substring(0, 1), LastName = modelTest.FullName.Substring(1, modelTest.FullName.Length - 1), Name = modelTest.FullName, CredentialsCode = "", Birthday = DateTime.Now, Sex = true, MobileNumber = "18000010001", Email = modelTest.Email, TelephoneNumber = "18000010001", Description = "", CreateDateTime = DateTime.Now, UpdateTime = DateTime.Now, InquiryPassword = "******", }; var user = new ApplicationUser() { UserName = modelTest.UserName, FirstName = modelTest.FullName.Substring(0, 1), LastName = modelTest.FullName.Substring(1, modelTest.FullName.Length - 1), ChineseFullName = modelTest.FullName, MobileNumber = "18000010001", Email = modelTest.Email, Person = person, }; var idManager = new IdentityManager(); idManager.CreateUser(user, model.PassWord); idManager.AddUserToRole(user.Id, "RegisterUser"); //return RedirectToAction(); return(Content("<script>alert('恭喜注册成功');location.href'" + Url.Action("login", "Account") + "</script>")); //} //用户的保存Person ApplicationUser //return View(); } }
static void Main(string[] args) { var mailService = new Mafly.Mail.Mail(); //参数:接收者邮箱、内容 //mailService.Send("*****@*****.**", "测试邮件发送!"); //参数:接收者邮箱、接收者名字、内容 //mailService.Send("*****@*****.**", "胡超级", "测试邮件发送!"); //参数:接收者邮箱、接收者名字、邮件主题、内容 mailService.Send("*****@*****.**", "胡超级", "这里是主题", "测试邮件发送!<h1 style='background-color:red'>这里是测试H1标签</h1>"); //使用MailInfo对象模式 参数:接收者邮箱、接收者名字、邮件主题、内容 //mailService.Send(new MailInfo //{ // Receiver = "*****@*****.**", // ReceiverName = "mafly", // Subject = "邮件发送", // Body = "测试邮件发送!" //}); //使用MailInfo对象模式 参数:接收者邮箱、接收者名字、邮件主题、内容、附件路径 //mailService.Send( // new MailInfo // { // Receiver = "*****@*****.**", // ReceiverName = "mafly", // Subject = "带附件邮件发送", // Body = "测试带附件邮件发送!" // }, "../../Program.cs"); //使用MailInfo对象模式 参数:接收者邮箱、接收者名字、邮件主题、内容、多附件路径 //mailService.Send( // new MailInfo // { // Receiver = "*****@*****.**", // ReceiverName = "mafly", // Subject = "带附件邮件发送", // Body = "测试带附件邮件发送!" // }, new Attachment("../../Program.cs"), new Attachment("../../App.config")); }