我正在编写一个通过类 SmtpClient 发送电子邮件的程序。我使用这段代码:
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());
}
但它只有在我切断“睡眠”线时才有效。为什么?我认为在此过程中休息一下是个好主意。