public ActionResult Index(FormCollection formCollection) { LetterToOfficial letterToOfficial = new LetterToOfficial { firstName = formCollection["FirstName"], lastName = formCollection["LastName"], email = formCollection["Email"], letter = formCollection["Letter"], emailSubject = formCollection["EmailSubject"], zipCode = formCollection["ZipCode"], officials = System.Text.RegularExpressions.Regex.Replace(formCollection["Officials"], @"\r\n+", " ") }; string[] officialsArray = null; // now split the contacts that are selected and loop officialsArray = letterToOfficial.officials.Split(','); string[] nameValuePair = null; for (int i = 0; i < officialsArray.Length -1; i++) { nameValuePair = officialsArray[i].Split('|'); var thisEmail = nameValuePair[0]; var thisName = nameValuePair[1]; MailHandler thisMailer = new MailHandler(); thisMailer.SendEmail(letterToOfficial.email, thisEmail, letterToOfficial.emailSubject, letterToOfficial.letter); } // do we save the submitee to the database? return View("ThankYou"); }
private void SaveEmail(string email, string fname, string lname, string zip, string ipAddress) { lock (SyncRoot) { string path = Server.MapPath(@"/App_Data/QuickJoins.txt"); bool existed = System.IO.File.Exists(path); using (StreamWriter sw = new StreamWriter(path, true, System.Text.Encoding.UTF8)) { if (!existed) { sw.WriteLine("Email\tFName\tLName\tZip\tIP\tDate"); } if (!Utils.IsValidName(fname)) fname = null; if (!Utils.IsValidName(lname)) lname = null; if (!Utils.IsValidEmail(email)) return; if (!Utils.IsValidZip(zip)) return; int ipCount = 0; if (_IPCount.TryGetValue(ipAddress, out ipCount) && ipCount > _MaxEntriesPerIP) return; _IPCount[ipAddress] = ipCount + 1; string el = email.ToLower().Trim(); if (_SeenEmails.ContainsKey(el)) return; //send email notice MailHandler thisMailer = new MailHandler(); Registrant registrant = new Registrant(); registrant.Email = email; registrant.FirstName = fname; registrant.LastName = lname; registrant.ZipCode = zip; thisMailer.SendContactEmail(registrant, "JOIN"); sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", email, fname, lname, zip, ipAddress, DateTime.Now.ToString("r")); _SeenEmails[el] = el; sw.Flush(); } } }
public ActionResult Index(Registrant registrant) { if (ModelState.IsValid) { db.Registrants.AddObject(registrant); db.SaveChanges(); MailHandler thisMailer = new MailHandler(); thisMailer.SendContactEmail(registrant); return RedirectToAction("ThankYou"); } return View(registrant); }