public JsonResult Test(TestEmailIM vm) { if (!ModelState.IsValid) { AR.Setfailure(GetModelErrorMessage()); return(Json(AR, JsonRequestBehavior.DenyGet)); } try { var emailAccount = _emailAccountService.GetById(vm.AccountId); var emailAccountIM = _mapper.Map <EmailAccountIM>(emailAccount); if (!string.IsNullOrEmpty(emailAccountIM.Password)) { var pw = EncryptionHelper.Decrypt(emailAccountIM.Password); emailAccountIM.Password = pw; } _emailService.SendMail(SettingsManager.Site.SiteName, emailAccountIM.Email, vm.TestEmail, string.Empty, "测试", "测试邮件", emailAccountIM.SmtpServer, emailAccountIM.Email, string.Empty, emailAccountIM.UserName, emailAccountIM.Password, emailAccountIM.Port, emailAccountIM.EnableSsl); AR.SetSuccess(String.Format(Messages.AlertSendSuccess, EntityNames.EmailAccount)); return(Json(AR, JsonRequestBehavior.DenyGet)); }catch (Exception er) { AR.Setfailure(er.Message); return(Json(AR, JsonRequestBehavior.DenyGet)); } }
public async Task <IActionResult> TestAsync(TestEmailIM vm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var emailAccount = await _context.EmailAccounts.FindAsync(vm.AccountId); if (!string.IsNullOrEmpty(emailAccount.Password)) { var pw = EncryptionHelper.Decrypt(emailAccount.Password); emailAccount.Password = pw; } _emailService.SendMail("TZGOA", vm.TestEmail, vm.TestEmail, string.Empty, "测试", "测试邮件", emailAccount.Smtpserver, emailAccount.Email, string.Empty, emailAccount.UserName, emailAccount.Password, emailAccount.Port, emailAccount.EnableSsl); return(Ok()); } catch (Exception er) { //AR.Setfailure(er.Message); return(BadRequest(er.Message)); } }
public ActionResult Test(int id) { EmailAccount emailAccount = _emailAccountService.GetById(id); if (emailAccount == null) { AR.Setfailure(Messages.HttpNotFound); return(Json(AR, JsonRequestBehavior.AllowGet)); } var vm = new TestEmailIM() { AccountId = emailAccount.Id }; return(PartialView("_Test", vm)); }