internal static void SendAppointmentRequest(AskForAppointmentInformation requestInfo, IConfiguration configuration) { SmtpClient client = GetSmtpClient(configuration); MailMessage mailMessage = GetMailMessageForAppointmentRequest(requestInfo); client.Send(mailMessage); }
internal string SendAppointmentRequest(AskForAppointmentInformation requestInfo, IConfiguration configuration) { if (requestInfo.UserId != "") { var user = Context.Users.First(c => c.Id == Convert.ToInt32(requestInfo.UserId)); requestInfo.Email = user.Email; var customer = Context.Customers.First(c => c.Id == user.IdCustomer); requestInfo.UserName = customer.FirstName + " " + customer.LastName; requestInfo.PhoneNumber = Context.PhoneNumbers.First(c => c.IdCustomer == customer.Id).Phone.ToString(); } EmailSender.SendAppointmentRequest(requestInfo, configuration); return(requestInfo.UserId); }
private static MailMessage GetMailMessageForAppointmentRequest(AskForAppointmentInformation requestInfo) { using (StreamReader reader = File.OpenText("EmailTemplate/askForAppointment.html")) { string newHtml = ""; MailMessage mailmessage = new MailMessage { IsBodyHtml = true, From = new MailAddress("*****@*****.**") }; mailmessage.To.Add(new MailAddress("*****@*****.**")); mailmessage.Subject = "Un client vous a envoyé une demande de rendez-vous"; var htmlFile = reader.ReadToEnd(); newHtml = htmlFile.Replace("[AppointmentTimeOfDayx]", requestInfo.TimeOfDay); newHtml = newHtml.Replace("[AppointmentDatex]", requestInfo.Date); newHtml = newHtml.Replace("[SenderEmailx]", requestInfo.Email); newHtml = newHtml.Replace("[OtherInformationx]", requestInfo.MoreInformation != "" ? "<div>Informations supplémentaires :</div><div class=\"moreInfoBorder\">" + requestInfo.MoreInformation + "</div>" : ""); newHtml = newHtml.Replace("[SenderPhoneNumberx]", requestInfo.PhoneNumber); newHtml = newHtml.Replace("[SenderNamex]", requestInfo.UserName); newHtml = newHtml.Replace("[AppointmentTypex]", requestInfo.TypeOfTreatment); mailmessage.Body = newHtml; return(mailmessage); } }
public ActionResult AskForAppointment([FromBody] AskForAppointmentInformation requestInfo) { return(Ok(Service.SendAppointmentRequest(requestInfo, configuration))); }