This is my code
foreach (String Email in usersList)
{
if(Regex.IsMatch(Email, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress AddressFrom = new MailAddress(emailFrom);
message.From = AddressFrom;
MailAddress AddressTo = new MailAddress(Email);
message.To.Add(Email);
smtpClient.Send(message);
message.Dispose();
smtpClient.Dispose();
}
}
I need to send an email to all users present in the list. But if an exception occurs, the loop breaks and the rest of emails won't be sent. There is other way I can do this so if an email can't be sent the loop keeps iterating and just ignore the ones that fail?
Thank you!