public ActionResult AddMeeting(MeetingModel model) { NameMeetingEvent meeting = new NameMeetingEvent { NameEvent = model.NameEvent }; _context.MeetingEvents.Add(meeting); _context.SaveChanges(); int a = _context.MeetingEvents.Count(); if (model.HeaderEvent.Count() > 0 && model.NameEvent.Count() > 0) { for (int i = 0; i < model.HeaderEvent.Count; i++) { MeetingInformation information = new MeetingInformation { MeetingID = _context.MeetingEvents.Count(), Header = model.HeaderEvent[i], Context = model.ContextEvent[i] }; _context.MeetingInformations.Add(information); _context.SaveChanges(); } } return(RedirectToAction("GetAllMeeting")); }
private void SendMail(MeetingInformation info) { try { var senderID = "*****@*****.**"; var senderPassword = "******"; StringBuilder emailBody = new StringBuilder(); string nextLine = "<br />"; // Email Body emailBody.AppendFormat("Dear {0},", "Admin"); emailBody.AppendLine(); emailBody.AppendFormat("This is a email to set up a meeting time.", nextLine, nextLine); emailBody.AppendFormat("The applicant's information is:", nextLine, nextLine); emailBody.AppendLine(); emailBody.AppendFormat("Name: {0}", info.Name, nextLine); emailBody.AppendLine(); emailBody.AppendFormat("Email: {0}", info.email, nextLine); emailBody.AppendLine(); emailBody.AppendFormat("Phone number: {0}", info.phonenumber, nextLine); emailBody.AppendLine(); emailBody.AppendFormat("Date and time to meet: {0}", info.dateandtime, nextLine); emailBody.AppendLine(); emailBody.AppendLine(); emailBody.AppendFormat("Email From", nextLine); emailBody.AppendFormat("Bot Template"); string body = emailBody.ToString(); MailMessage msg = new MailMessage(); msg.Body = body; msg.Subject = "Scheduling meeting for client"; msg.From = new MailAddress("*****@*****.**"); msg.To.Add(new MailAddress("*****@*****.**")); msg.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient("smtp.gmail.com")) { smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new NetworkCredential(senderID, senderPassword); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(msg); } } catch (Exception ex) { var exInfo = new { message = ex.Message, innerException = ex.InnerException, stackTrace = ex.StackTrace }; //var filePath = Server.MapPath(@"\Data\OutPut.txt"); // System.IO.File.AppendAllText(filePath, "\n" + exInfo.ToString() + "," + DateTime.UtcNow.ToString()); } }