public ActionResult Index(Send Savemail) { List <SelectListItem> ulkekodu = (from i in db.TelKodu.ToList() select new SelectListItem { Text = i.UlkeKodu, Value = i.Id.ToString() }).ToList(); ViewBag.bag = ulkekodu; try { try { string[] email = Savemail.Kime.Split(';'); for (int i = 0; i < email.Count(); i++) { results = EmailExtension.EmailRegex(email[i]); } if (results.ResultErrorList.Count > 0) { ModelState.AddModelError("Kime", "Email girişlerinde hatalı bir email mevcut"); return(View(Savemail)); } else { foreach (var item in email) { var senderEmail = new MailAddress("*****@*****.**", "Edanur"); var receiverEmail = new MailAddress(item, "Receiver"); var password = "******"; var sub = Savemail.Konu; var body = Savemail.Mesaj + " " + Savemail.Kim + " " + Savemail.Telefon; var smtp = new SmtpClient() { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(senderEmail.Address, password) }; using (var mess = new MailMessage(senderEmail, receiverEmail) { Subject = Savemail.Konu, Body = body }) smtp.Send(mess); db.Send.Add(Savemail); db.SaveChanges(); } } return(View()); } catch (NullReferenceException exception) { ModelState.AddModelError("Kime", "Email alanı boş olamaz"); return(View()); } } catch (Exception ex) { throw new Exception(ex.Message); } }