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
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,280 questions
{count} votes