public ActionResult SendEmail(checkintegration.Models.Sendmail okay, int id = 0) { InsureEntities db = new InsureEntities(); AccidentInfo ai = new AccidentInfo(); Registration rg = new Registration(); var sid = db.AccidentInfoes.Where(m => m.AccidentId == id).Select(m => m.SurveyorId).FirstOrDefault(); var smail = db.Registrations.Where(m => m.UserID == sid).Single(); var cid = db.AccidentInfoes.Where(m => m.AccidentId == id).Select(m => m.CustId).FirstOrDefault(); var cmail = db.Registrations.Where(m => m.UserID == cid).Single(); MailMessage mail = new MailMessage(); mail.To.Add(smail.EmailId); mail.From = new MailAddress("*****@*****.**"); mail.Subject = "Information about your Client"; string Body = "Client FullName :" + cmail.FirstName + " " + cmail.LastName + "\n" + "\n Client Email ID:" + cmail.EmailId + "\n" + "\nClient Gender:" + cmail.Gender + "\n" + "\nClient Phone number:" + cmail.PhoneNumber + "\n" + "\nClient Address:" + cmail.Address + " " + cmail.Pincode; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "jethalal004"); // Enter seders User name and password smtp.EnableSsl = true; smtp.Send(mail); ViewBag.Error = "Information has been sent to registered mail id"; mail.To.Add(cmail.EmailId); mail.From = new MailAddress("*****@*****.**"); mail.Subject = "Information about your Surveyor"; string info = "Surveyor FullName :" + smail.FirstName + " " + smail.LastName + "\n" + "\n Surveyor Email ID:" + smail.EmailId + "\n" + "\nSurveyor Gender:" + smail.Gender + "\n" + "\nSurveyor Phone number:" + smail.PhoneNumber + "\n" + "\nSurveyor Address:" + smail.Address + " " + smail.Pincode; mail.Body = info; mail.IsBodyHtml = true; // SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "jethalal004"); // Enter seders User name and password smtp.EnableSsl = true; smtp.Send(mail); ViewBag.Error = "Information has been sent to registered mail id"; return(View("View_Accident")); return(View()); }
public ActionResult ForgotPassword(checkintegration.Models.Sendmail okay) { try { if (ModelState.IsValid) { InsureEntities db = new InsureEntities(); var email = db.Registrations.Where(a => a.EmailId == okay.To).FirstOrDefault(); if (email != null) { var pass = db.Registrations.Where(a => a.EmailId == okay.To).Select(a => new { Password = a.Password }).Single(); MailMessage mail = new MailMessage(); mail.To.Add(okay.To); mail.From = new MailAddress("*****@*****.**"); mail.Subject = "Forgot Password"; string Body = "Your Password is:" + pass.Password; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "jethalal004"); // Enter seders User name and password smtp.EnableSsl = true; smtp.Send(mail); ViewBag.Error = "Password has been sent to registered mail id"; return(View("LogIn")); } else { ViewBag.Error = "Email not Found"; return(View(okay)); } } else { ViewBag.Error = "Some Error Occured"; return(View(okay)); } } catch (Exception e) { ViewBag.Error = "Error Occured"; return(View("ForgotPassword", okay)); } }