I am writing a program that sends email through class SmtpClient. I use this code:
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("mailSMTP.it");
mail.From = new MailAddress("address.it");
mail.Subject = "oggetto";
mail.IsBodyHtml = true;
string htmlBody = "someHTML";
mail.Body = htmlBody;
SmtpServer.Port = 25;
SmtpServer.EnableSsl = false;
foreach (string indirizzo in indirizzi)
{
mail.To.Clear();
mail.To.Add(indirizzo);
SmtpServer.Send(mail);
System.Threading.Thread.Sleep(3000);
}
MessageBox.Show("e-mail spedite!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
but it only works if I cut the "Sleep" line. Why? I thought it was a good idea to make a rest during that process.