private async Task sendEmail(string SendtoEmail, string subject, string bodyMessage, string filename, string optionalParam) { try { string body; using (var sr = new StreamReader(Server.MapPath("\\Helpers\\") + filename)) { body = sr.ReadToEnd(); } Mailer mailer = new Mailer(); mailer.ToEmail = SendtoEmail; mailer.Subject = subject; if (optionalParam == "") mailer.Body = string.Format(body, bodyMessage); else mailer.Body = string.Format(body, bodyMessage, optionalParam); mailer.IsHtml = true; await mailer.Send(); } catch (Exception e) { } }
public async Task<ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByEmailAsync(model.Email); if (user == null) { // Don't reveal that the user does not exist or is not confirmed return View("ForgotPasswordConfirmation"); } string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); string body; using (var sr = new StreamReader(Server.MapPath("\\Helpers\\") + "passwordreset.html")) { body = sr.ReadToEnd(); } try { Mailer.GmailUsername = "******"; Mailer.GmailPassword = "******"; var email = model.Email; Mailer mailer = new Mailer(); mailer.ToEmail = model.Email; mailer.Subject = "Reset your Password MezoExperts.com"; mailer.Body = string.Format(body, "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); mailer.IsHtml = true; mailer.Send(); } catch (Exception e) { } //await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); return RedirectToAction("ForgotPasswordConfirmation", "Account"); } // If we got this far, something failed, redisplay form return View(model); }