Sending email to multiple uers using asp.net mvc5

gcobani.mkontwana 1 Reputation point
2021-11-22T09:09:30.597+00:00

Hi Team

I want to send email to multiple users and need some help with my logic below;

// Sending email notification to a user.

    public static class EmailNotificationToUser
    {
        public static void SendEmail(string htmlString,string emailGrp, string ToEmail)
        {
            try
            {
                MailMessage message = new MailMessage();
                SmtpClient smtp = new SmtpClient();
                message.From = new MailAddress("gcobani.mkontwana@s4.co.za");
                List<MailAddress> addresses = new List<MailAddress>();
                string[] emilGrp = ToEmail.Split(',');
                foreach(string Multiemail in emailGrp)
                {
                    message.To.Add(new MailAddress(Multiemail));
                }


                message.To.Add(emailGrp);
                message.Subject = "ShopFloor AMS Incident Report";
                message.IsBodyHtml = true;
                message.Body = htmlString;
                smtp.Port = 587;
                smtp.Host = "smtp.gmail.com";
                smtp.EnableSsl = true;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new NetworkCredential("entsagcobza2020@gmail.com", "Telkom800@@");
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtp.Send(message);


            }catch(Exception ex)
            {

            }
        }
    }
ASP.NET MVC
ASP.NET MVC
A Microsoft web application framework that implements the model-view-controller (MVC) design pattern.
609 questions
{count} votes