public void ProcessParticipantInfo(ParticipantInfo participantInfo) { using (var smtpClient = new SmtpClient()) { smtpClient.Host = emailSettings.ServerName; smtpClient.Port = emailSettings.ServerPort; if (emailSettings.WriteAsFile) { smtpClient.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory; smtpClient.PickupDirectoryLocation = emailSettings.FileLocation; smtpClient.EnableSsl = false; } emailSettings.MailToAddress = participantInfo.MailToAddress; StringBuilder body = new StringBuilder() .AppendLine("Credit Union Name: " + participantInfo.CreditunionName + "\n") .AppendLine("Contact Name: " + participantInfo.ContactName + "\n") .AppendLine("Phone Number: " + participantInfo.PhoneNumber + "\n") .AppendLine("Email Address: " + participantInfo.EmailAddress + "\n") .AppendLine("Interested in: " + "\n") .AppendLine(participantInfo.InterestedIn); MailMessage mailMessage = new MailMessage( emailSettings.MailFromAddress, // From emailSettings.MailToAddress, // To participantInfo.Subject, // Subject body.ToString()); // Body if (emailSettings.WriteAsFile) { mailMessage.BodyEncoding = Encoding.ASCII; } smtpClient.Send(mailMessage); } }
public ActionResult ParticipationSignUp(ParticipantInfo participantinfo) { if (ModelState.IsValid) { if (!ArithmeticCaptcha.isValid(Request["ArithmeticValue"], Request["ArithmeticValueEnc"])) { //ModelState.AddModelError("ArithmeticValue", "Wrong number. Please try again."); ViewBag.WrongNumber = "Wrong number. Please try again."; } else { ViewBag.Successful = "Your Form has been submitted successfully!"; ViewBag.WrongNumber = ""; StringBuilder sb = new StringBuilder(); string mailtoAddress = ConfigurationManager.AppSettings["Email.To.General"]; // get interested in items string cre = Request.Form.GetValues("CRE")[0]; string sbs = Request.Form.GetValues("SBS")[0]; string sba = Request.Form.GetValues("SBA")[0]; string mbl = Request.Form.GetValues("MBL")[0]; if (cre == "true") { sb.AppendLine("Commercial Real Estate"); } if (sbs == "true") { sb.AppendLine("Small Business Services"); } if (sba == "true") { sb.AppendLine("Small Business Administration"); } if (mbl == "true") { sb.AppendLine("Member Business Lending"); } //*** for testing ************************************ //mailtoAddress = "*****@*****.**"; if (!String.IsNullOrEmpty(mailtoAddress)) { participantinfo.InterestedIn = sb.ToString(); participantinfo.Subject = "Participant Request Form"; participantinfo.MailToAddress = mailtoAddress; // send email processor.ProcessParticipantInfo(participantinfo); } } } return View(); }