Hi,
I have a list of email with , in the database. I want to use these email as recipient for email sending.
Example: Sarah_Handerson@gmail.com, Alex_Benjamin@gmail.com, Zac@gmail.com
i also want the name of the email before @. I already did with one email and it works but for multiple email, i tried to split by comma but failed.
Output : Sarah_Handerson, Alex_Benjamin,Zac
 Email code
        public void EmailService(string EmailFrom, string subject, string body)
        {
            MailMessage message = new MailMessage();
            var query = db.GuestList.ToList();
            foreach (var item in query)
            {
               for (int i = 1; i < item.GuestName.Split(',').Length; i++)
                {
                    message.To.Add(item.GuestName.Split(',')[i]);
                }
                message.To.Add(item.vipName);
            }
            message.From = new MailAddress(EmailFrom, "Party Invitation");
            message.Subject = subject;
            message.Body = body;
            message.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();
            smtp.Send(message);
        }
 
Save substring code
        [HttpPost]
        public ActionResult AddDetails(partyModel pm)
        {
            string guest= pm.guestEmail
            guest = guest.Substring(0, guest.IndexOf("@"));
            //for (int i =1; i < pm.GuestName.Split(',').Length; i++)
            //{
            //    var guest = pm.GuestName.Split(',')[i];
            //}
            string vip = pm.vipEmail;
            vip = vip.Substring(0, vip.IndexOf("@"));
            EnM a = new EnM();
            a.Selection = pm.Selection;
            a.GuestName = guest;
            a.GuestEmail = pm.GuestEmail;
            a.guestName = guest;
            a.vipEmail = pm.vipEmail;
	    a.vipName = vip;
            
            db.EnMS.Add(a);
            db.SaveChanges();
           
            return RedirectToAction("NewForm");
        }