private void button1_Click(object sender, EventArgs e) { try { System.IO.File.WriteAllText(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\razortester.txt", tbData.Text); System.IO.File.WriteAllText(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\razortester2.txt", tbTemplate.Text); data = new JsonReader().Read(tbData.Text); RazorEngine.Templating.TemplateService svc = new RazorEngine.Templating.TemplateService(); tbCompiled.Text = svc.Parse(tbTemplate.Text, data, null, null); webBrowser1.DocumentText = tbCompiled.Text; } catch (Exception ex) { MessageBox.Show(ex.Message); tbOutput.Text = ex.ToString(); } }
public IHttpActionResult GetForgotPassword(UserMail userMail) { if (userMail == null || string.IsNullOrEmpty(userMail.Mail) || string.IsNullOrWhiteSpace(userMail.Mail)) { return(NotFound()); } var user = db.Users.FirstOrDefault(u => u.Email.Trim().ToLower() == userMail.Mail.Trim().ToLower()); if (user == null) { return(NotFound()); } EmailService emailService = new EmailService(); ForgotPasswordEmailModel model = new ForgotPasswordEmailModel { Name = user.UserName, Password = Protector.Decrypt(user.Password) }; var templateService = new RazorEngine.Templating.TemplateService(); var templateFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Services", "Email", "ForgotPasswordEmailTemplate.cshtml"); var emailHtmlBody = templateService.Parse(File.ReadAllText(templateFilePath), model, null, null); try { IdentityMessage msg = new IdentityMessage(); msg.Subject = "Loglig"; msg.Body = emailHtmlBody; msg.Destination = user.Email; emailService.SendAsync(msg); } catch (Exception ex) { return(InternalServerError()); } return(Ok()); }
private static void tep_mail(string to_name, string to_email_address, string email_subject, string email_text, string from_email_name, string from_email_address, string file_location = "", string file_name = "", bool bcc = false) { try { //var emailHtmlBody = templateService.Parse(welcomeEmailTemplate, model, null, "WelcomeEmail"); if (bcc == true) { string bcc_email_address = BCC_EMAIL_ADDRESS; //send mail } else { //send mail } if (EMAIL_USE_HTML == "true") { } else { } // Send the process report. RazorEngine.Templating.TemplateService razor = new RazorEngine.Templating.TemplateService(); MailMessage message = new MailMessage(); SmtpClient server = new SmtpClient(ConfigurationManager.AppSettings["emailServer"]); message.From = new MailAddress("*****@*****.**"); message.To.Add(ConfigurationManager.AppSettings["reportEmailRecipients"]); message.Subject = string.Format("Razor Email Test"); message.IsBodyHtml = true; Model.UserDetail model = new Model.UserDetail() { Name = "Gene Buryakovsky", Address = "" }; message.Body = razor.Parse(File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template", "RenewalEmailTemplate.cshtml")), model, null, null); } catch (Exception e) { Console.WriteLine(e.Message); EventLog.WriteEntry(sSource, e.Message); //return string.Empty; } }