public ViewResult Learner_Home(Logging_System.Models.Email _objModelMail) { if (ModelState.IsValid) { MailMessage mail = new MailMessage(); mail.To.Add(_objModelMail.Sendto); mail.From = new MailAddress(_objModelMail.SentFrom); mail.Subject = _objModelMail.Subject; string Body = _objModelMail.Message; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; //smtp.Port = 465; //smtp.Port = 2525; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential ("*****@*****.**", "Jedia.01"); smtp.EnableSsl = true; smtp.Send(mail); ViewBag.Message = "Sent"; return(View("Learner_Home")); } else { return(View()); } }
public ViewResult Learner_Home(Logging_System.Models.Email _objModelMail) { if (ModelState.IsValid) { string mails = "*****@*****.**"; _objModelMail.SentFrom = mails; if (_objModelMail.Sendto == "Log System Support") { _objModelMail.Sendto = "*****@*****.**"; } else if (_objModelMail.Sendto == "Prudence Mabitsela") { _objModelMail.Sendto = "*****@*****.**"; } else if (_objModelMail.Sendto == "Mthunzi Huna") { _objModelMail.Sendto = "*****@*****.**"; } else if (_objModelMail.Sendto == "Mojalefa Tsao") { _objModelMail.Sendto = "*****@*****.**"; } else { _objModelMail.Sendto = "*****@*****.**"; } MailMessage mail = new MailMessage(); mail.To.Add(_objModelMail.Sendto); mail.From = new MailAddress(mails); mail.Subject = _objModelMail.Subject + " Ticket|Reference: " + _objModelMail.Ticket; string Body = _objModelMail.Message; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; //smtp.Port = 465; //smtp.Port = 2525; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential ("*****@*****.**", "Jedia.01"); smtp.EnableSsl = true; smtp.Send(mail); _objModelMail.Error = "Your email has been successfully sent!"; ViewBag.Message = _objModelMail.Error; return(View("Learner_Home")); } else { return(View()); } }