public async Task SendEmail(EmailDom emailModel) { string apiKey = Configuration["APIKEY"]; SendGridClient client = new SendGridClient(apiKey); SendGridMessage msg = MailHelper.CreateSingleEmail(emailModel.From, emailModel.To, emailModel.Subject, emailModel.PlainTemplate, emailModel.HtmlTemplate); await client.SendEmailAsync(msg); }
public async Task SendEmail(AppointAdd model, int id) { string EmailToken = Guid.NewGuid().ToString(); //Create the send model and assign the data EmailDom sendModel = new EmailDom(); sendModel.To = new EmailAddress(model.Email, model.CustFName + " " + model.CustLName); sendModel.From = new EmailAddress(model.CompEmail, model.CompName); //assign links and change formats of zip and appoinment date and time to appear correctly in the email string link = "http://localhost:51285/Account/CfrmAppoint/" + id; string editlink = "http://localhost:51285/Account/CustomerEdit/" + id; string zip = (model.Zip).ToString(); string appoint = model.Appoint.ToString("MM/dd/yyyy hh:mm tt"); sendModel.Subject = "Your Appointment with " + model.CompName; //build email and input correct information sendModel.HtmlTemplate = System.IO.File.ReadAllText("Models/EmailModels/ConfirmTemp.txt"); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{appoint}", appoint); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{firName}", model.CustFName); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{lasName}", model.CustLName); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{street}", model.Street); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{city}", model.City); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{state}", model.State); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{zip}", zip); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{email}", model.Email); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{phone}", model.Phone); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{{ConfirmUrl}}", link); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{{EditUrl}}", editlink); //plain email for emails that cannot accept the HtmlTemplate sendModel.PlainTemplate = System.IO.File.ReadAllText("Models/EmailModels/ConfirmTempPlain.txt"); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{appoint}", appoint); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{firName}", model.CustFName); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{lasName}", model.CustLName); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{street}", model.Street); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{city}", model.City); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{state}", model.State); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{zip}", zip); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{email}", model.Email); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{phone}", model.Phone); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{{ConfirmUrl}}", link); sendModel.PlainTemplate = sendModel.PlainTemplate.Replace("{{EditUrl}}", editlink); //Send the email await SendEmail(sendModel); }
public Task SendEmailAsync(string email, string subject, string callbackUrl, string apiKey) { EmailDom sendModel = new EmailDom(); sendModel.To = new EmailAddress(email); sendModel.From = new EmailAddress("*****@*****.**", "me"); sendModel.Subject = "Reset your password"; sendModel.HtmlTemplate = System.IO.File.ReadAllText("Models/EmailModels/ForgotPass.txt"); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{{ConfirmUrl}}", callbackUrl); sendModel.PlainTemplate = System.IO.File.ReadAllText("Models/EmailModels/ResetPassPlain.txt"); sendModel.PlainTemplate = sendModel.HtmlTemplate.Replace("{{ConfirmUrl}}", callbackUrl); SendGridClient client = new SendGridClient(apiKey); SendGridMessage msg = MailHelper.CreateSingleEmail(sendModel.From, sendModel.To, sendModel.Subject, sendModel.PlainTemplate, sendModel.HtmlTemplate); return(client.SendEmailAsync(msg)); }
public static Task SendEmailConfirmationAsync(this IEmailSender emailSender, string email, string link, string apiKey) { EmailDom sendModel = new EmailDom(); sendModel.To = new EmailAddress(email); sendModel.From = new EmailAddress("*****@*****.**", "me"); sendModel.Subject = "Welcome to App!"; string cfrmLink = HtmlEncoder.Default.Encode(link); sendModel.HtmlTemplate = System.IO.File.ReadAllText("Models/EmailModels/ConfirmEmail.txt"); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{{ConfirmUrl}}", cfrmLink); sendModel.PlainTemplate = System.IO.File.ReadAllText("Models/EmailModels/ConfirmEmailPlain.txt"); sendModel.PlainTemplate = sendModel.HtmlTemplate.Replace("{{ConfirmUrl}}", cfrmLink); SendGridClient client = new SendGridClient(apiKey); SendGridMessage msg = MailHelper.CreateSingleEmail(sendModel.From, sendModel.To, sendModel.Subject, sendModel.PlainTemplate, sendModel.HtmlTemplate); return(client.SendEmailAsync(msg)); }
//Hangfire Method public async Task GetAppointments() { cmd.CommandText = "Appointment_HFSelectAll"; conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); var emails = new List <AppointDom>(); while (reader.Read()) { emails.Add(new AppointDom { Id = Convert.ToInt32(reader["Id"]), CustFName = Convert.ToString(reader["CustFName"]), CustLName = Convert.ToString(reader["CustLName"]), Email = Convert.ToString(reader["Email"]), Appoint = Convert.ToDateTime(reader["Appoint"]), IsCnfrmed = Convert.ToBoolean(reader["IsCnfrmed"]), ReminderSent = Convert.ToBoolean(reader["ReminderSent"]), CompName = Convert.ToString(reader["CompName"]), CompEmail = Convert.ToString(reader["CompEmail"]) }); } conn.Close(); //notify the database that a reminder email has been sent foreach (AppointDom email in emails) { UpdateReminder(email); } //Send appointment reminder to customers foreach (AppointDom email in emails) { //create link and convert appointment string link = "http://*****:*****@App.com"); sendModel.Subject = "Reminder for your upcoming appointment with " + email.CustFName + " " + email.CustLName; sendModel.HtmlTemplate = System.IO.File.ReadAllText("Models/EmailModels/ReminderEmail.txt"); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{CompName}", email.CustFName); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{Appoint}", appoint); sendModel.PlainTemplate = System.IO.File.ReadAllText("Models/EmailModels/ReminderEmailPlain.txt"); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{CompName}", email.CustFName); sendModel.HtmlTemplate = sendModel.HtmlTemplate.Replace("{Appoint}", appoint); await SendEmail(sendModel); } }