Yes, but your code could use a decent amount of work.
using (SmtpClient smtpClient = new SmtpClient())
{
foreach (String Email in usersList)
{
if(Regex.IsMatch(Email, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")
{
using (MailMessage message = new MailMessage())
{
try
{
MailAddress AddressFrom = new MailAddress(emailFrom);
message.From = AddressFrom;
MailAddress AddressTo = new MailAddress(Email);
message.To.Add(Email);
smtpClient.Send(message);
}
catch (Exception e)
{
// log exception and keep going
}
}
}
}
}
Firstly, stop calling Dispose()
! When you get that exception, do you know what happens? Dispose()
never gets called. Bring you smtp allocation outside of the loop so it's not re-allocated on every iteration. Then just add a try-catch and suppress the exceptions, log them, write them to the console, whatever.