public ViewResult Index(Models.MailModel _objModelMail) { if (ModelState.IsValid) { MailMessage mail = new MailMessage(); mail.To.Add(_objModelMail.To); mail.From = new MailAddress(_objModelMail.From); mail.Subject = _objModelMail.Subject; string Body = _objModelMail.Body; 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("*****@*****.**", "1234Nabidbhuiaisahealer."); // Enter seders User name and password smtp.EnableSsl = true; smtp.Send(mail); return(View("Index", _objModelMail)); } else { return(View()); } }
public ViewResult Index(Models.MailModel _objModelMail) { if (ModelState.IsValid) { //Instância classe email MailMessage mail = new MailMessage(); mail.To.Add(_objModelMail.To); mail.From = new MailAddress(_objModelMail.From); mail.Subject = _objModelMail.Subject; string Body = _objModelMail.Body; mail.Body = Body; mail.IsBodyHtml = true; //Instância smtp do servidor, neste caso o gmail. SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential ("*****@*****.**", "Segredo2");// Login e senha do e-mail. smtp.EnableSsl = true; smtp.Send(mail); ModelState.Clear(); return(View()); } else { return(View()); } }
public bool SendMail(CandidateExamBookingDetail candidateExamBookingDetail) { try { string message = ""; //Here we will save data to the database DateTime bookedDate = Convert.ToDateTime(candidateExamBookingDetail.BookedDate); string slotname = db.ExamSlots.Where(s => s.SlotId == candidateExamBookingDetail.SlotId).FirstOrDefault().SlotName; string ToEmail = db.CandidateDetails.Where(c => c.CandidateId == candidateExamBookingDetail.CandidateId).FirstOrDefault().Email; //check username available byte[] bytes = null; MailModel mm = new Models.MailModel(); mm.To = ToEmail; mm.From = "*****@*****.**"; mm.Body = "Dear " + candidateExamBookingDetail.CandidateDetail.FirstName + ", <br /> <br />Thank you for booking exam with TADE. <br /><br />Your exam has been booked on " + bookedDate.ToString("dd/MM/yyyy") + " at " + slotname + ".<br /><br /><u>To attend the exam:</u><br /><br />Please read the registration confirmation email for exam details.<br /><br /> Kind Regards <br /> TADE Admin Team"; mm.Subject = "TADE exam booking confirmation"; message = "Exam booking confirmation"; SendMailBLL sm = new SendMailBLL(); sm.SendMail(mm, bytes); return(true); } catch (Exception ex) { return(false); } }
public ViewResult Index(Models.MailModel _objModelMail) { if (ModelState.IsValid) { MailMessage mail = new MailMessage(); mail.To.Add(new MailAddress("*****@*****.**")); mail.From = new MailAddress(_objModelMail.From); mail.Subject = _objModelMail.Subject + " from: " + _objModelMail.FullName; string Body = "<p>" + _objModelMail.Subject + " from: " + _objModelMail.FullName + "</p> " + _objModelMail.Body; 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 ("*****@*****.**", "ATS3....");// Enter senders User name and password smtp.EnableSsl = true; smtp.Send(mail); return(View("Success", _objModelMail)); } else { return(View()); } }
private Models.MailModel GetMailSetting() { Models.MailModel m = new Models.MailModel(); m.Port = 0; m.Email = ""; m.Host = ""; return(m); }
public static IEnumerable <MessageModel> SearchCache(string subPath) { var basePath = Path.Combine(Properties.Settings.Default.MailDir, subPath); foreach (var messagePath in messageCache.Keys) { var mailModel = new Models.MailModel(messagePath); if (messagePath == Path.Combine(basePath, mailModel.MessageId)) { yield return(mailModel); } } }
public bool SendMail(CandidateDetail candidateDetail) { string message = ""; //Here we will save data to the database //check username available byte[] bytes = null; MailModel mm = new Models.MailModel(); mm.To = candidateDetail.Email; mm.From = "*****@*****.**"; mm.Body = "Dear " + candidateDetail.FirstName + ", " + MailBody(candidateDetail.ExamId.ToString()); mm.Subject = "TADE registration confirmation"; message = "Confirmation"; SendMailBLL sm = new SendMailBLL(); sm.SendMail(mm, bytes); return(true); }
public string Index(Models.MailModel _objModelMail) { try { MailMessage mail = new MailMessage(); mail.To.Add("*****@*****.**"); mail.From = new MailAddress(_objModelMail.From); mail.Subject = _objModelMail.Subject; string body = _objModelMail.Body; mail.Body = body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "mail.noip.com"; smtp.Port = 587; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential("", ""); //Removed for security smtp.EnableSsl = true; smtp.Send(mail); return("Your message has been sent. Click the Close button to close this form."); } catch (System.Exception) { return("An error occured and your message was not sent. Please contact [email protected] to let them know something went wrong."); } }
public ActionResult UpdateMailConfig(Models.MailModel m) { return(PartialView("index", settingModel)); }
public bool SendMail(DrivingTestResult dr) { string message = ""; //Here we will save data to the database //check username available if (dr.Email != null) { using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { StringBuilder sb = new StringBuilder(); sb.Append("<h1 style='text - align: center; '>TADE EXAM RESULT</h1><p> </p>"); sb.Append("<table style='width: 100 % '><tbody><tr><td colspan='2'><h2>APPLICANT DETAILS</h2></td></tr><tr><td>1. FIRST NAME:</td><td>"); sb.Append(dr.FirstName); sb.Append("</td></tr><tr><td>2. MIDDLE NAME:</td><td>"); sb.Append(dr.MiddleName); sb.Append("</td></tr><tr><td>3. LAST NAME:</td><td>"); sb.Append(dr.LastName); sb.Append("</td></tr><tr><td>4. DATE OF BIRTH</td><td>"); sb.Append(dr.DateOfBirth); sb.Append("</td></tr><tr><td>5. DRIVING LICENCE No.</td><td>"); sb.Append(dr.DrivingLicense); sb.Append("</td></tr><tr><td>6. ADDRESS</td><td>"); sb.Append(dr.Address); sb.Append(" </td></tr><tr><td colspan='2'><h2>EXAM DETAILS</h2></td></tr><tr><td>7. REGISTRATION No.</td><td>"); sb.Append(dr.ExamId); sb.Append("</td></tr><tr><td>8. IP ADDRESS OF COMPUTER TEST ATTENDED</td><td>"); sb.Append(dr.IPAddress); sb.Append("</td></tr><tr><td>9. EXAMINER ID</td><td>"); sb.Append(" "); sb.Append("</td></tr><tr><td>10. TIME OF EXAM</td><td>"); sb.Append(" "); sb.Append("</td></tr><tr><td>11. DURATION OF EXAM</td><td>"); sb.Append(" "); sb.Append(" </td></tr><tr><td>12. EXAM GRADE</td><td>"); sb.Append(dr.Grade); sb.Append("</td></tr><tr><td>13. EXAM RESULT VALID TILL</td><td>"); sb.Append(" "); sb.Append(" </td></tr><tr><td>14. COMMENTS</td><td>"); sb.Append(dr.Explanation); sb.Append("</td></tr></tbody></table>"); StringReader sr = new StringReader(sb.ToString()); Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); using (MemoryStream memoryStream = new MemoryStream()) { PdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); string thesavePath = Server.MapPath("~/CandidateExamResults") + "\\" + dr.ExamId.ToString() + ".pdf"; System.IO.File.WriteAllBytes(thesavePath, bytes); MailModel mm = new Models.MailModel(); mm.To = dr.Email; mm.From = "*****@*****.**"; mm.Body = "Dear " + dr.FirstName + ", <br /> <br />Congratulations! You have successfully completed TADE exam. Please find attached certificate for future reference. <br /><br /> Kind Regards <br /> TADE Admin Team"; mm.Subject = "TADE exam result"; message = "Success"; SendMailBLL sm = new SendMailBLL(); sm.SendMail(mm, bytes); } } } } else { message = "Failed!"; } return(true); }
public ActionResult Create(Models.MailModel objModelMail, [Bind(Include = "MissionID,staffid,FromDate,ToDate,MissionItinerary,funding,ClearedBySupervisor,MissionObjective,ExpectedOutputs,FollowUp,SignatureDate")] MissionAuthorization missionAuthorization) { if (ModelState.IsValid) { db.MissionAuthorizations.Add(missionAuthorization); try { db.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } var staffs = db.staffs.Include(s => s.contract_details).Include(s => s.contract_type).Include(s => s.Country_office).Include(s => s.functional_title).Include(s => s.staff2).Include(s => s.sub_office).Include(s => s.unit).Include(s => s.country).Include(s => s.governorate); staffs = staffs.Where(s => s.staff_email.Contains(User.Identity.Name + "@wfp.org")); //ViewBag.staffid = new SelectList(db.staffs, "staffs.First().staffid", staffs.First().staff_email); ViewBag.staffid = staffs.First().staffid; ViewBag.staffid2 = staffs.First().staff_first_name; ViewBag.FirstName = staffs.First().staff_first_name; ViewBag.LastName = staffs.First().staff_last_name; ViewBag.Unit = staffs.First().unit.unit_description_english; var staffsupervisor = staffs.First().staff_supervisorid; var supers = db.staffs.Include(d => d.contract_details).Include(d => d.contract_type).Include(d => d.Country_office).Include(d => d.functional_title).Include(d => d.staff2).Include(d => d.sub_office).Include(d => d.unit).Include(d => d.country).Include(d => d.governorate); supers = supers.Where(d => d.staffid == staffsupervisor); var to = supers.First().staff_email; MailMessage mail = new MailMessage(); mail.To.Add(to); mail.From = new MailAddress("*****@*****.**"); mail.Subject = "Mission Authorization Form"; string Body = "Request : Mission Mission ID : " + missionAuthorization.MissionID + " <br> " + " From :" + staffs.First().staff_first_name + " " + staffs.First().staff_last_name + "<br><br>" + " Mission Information" + "<br><br>" + " From :" + missionAuthorization.FromDate + " To :" + missionAuthorization.ToDate + "<br>Funding :" + missionAuthorization.funding + " " + "Objective :" + missionAuthorization.MissionObjective; mail.Body = Body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtprelay.global.wfp.org"; smtp.Port = 25; smtp.UseDefaultCredentials = true; //smtp.Credentials = new System.Net.NetworkCredential //("ahmed.badr", "Survivor2323");// Enter seders User name and password //smtp.EnableSsl = true; smtp.Send(mail); //string from = "*****@*****.**"; ////Replace this with your own correct Gmail Address //string to = "*****@*****.**"; ////Replace this with the Email Address ////to whom you want to send the mail //System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); //mail.To.Add(to); //mail.From = new MailAddress(from); //mail.Subject = "This is a test mail"; //mail.SubjectEncoding = System.Text.Encoding.UTF8; //mail.Body = "This is Email Body Text"; //mail.BodyEncoding = System.Text.Encoding.UTF8; //mail.IsBodyHtml = true; //mail.Priority = MailPriority.High; //SmtpClient client = new SmtpClient("smtp.WFPEGSIMSP01.global.wfp.org", 25); ////Add the Creddentials- use your own email id and password //System.Net.NetworkCredential nt = //new System.Net.NetworkCredential("ahmed.badr", "Survivor2323"); //client.Port = 25; // Gmail works on this port //client.EnableSsl = false; //Gmail works on Server Secured Layer //client.UseDefaultCredentials = true; //client.Credentials = nt; //client.Send(mail); // var body = "<p>Email From: {0} ({1})</p><p>Message:</p><p>{2}</p>"; // var message = new MailMessage(); // message.To.Add(new MailAddress("*****@*****.**")); // replace with valid value // message.From = new MailAddress("*****@*****.**"); // replace with valid value // message.Subject = "Your email subject"; // message.Body = string.Format(body,"hhh","hjkjh","kjlkjl"); // message.IsBodyHtml = true; // using (var smtp = new SmtpClient()) // { // var credential = new NetworkCredential // { // UserName = "******", // replace with valid value // Password = "******" // replace with valid value // }; // smtp.Credentials = credential; // smtp.Host = "smtprelay.global.wfp.org"; // smtp.Port = 25; // smtp.EnableSsl = true; // smtp.SendMailAsync(message); return(RedirectToAction("Index")); // } //} } //ViewBag.staffid = User.Identity.GetUserName() + "@wfp.org"; return(RedirectToAction("Create")); }
public ActionResult Success(Models.MailModel _objModelMail) { return(View(_objModelMail)); }