这是我的代码
for(int i = 0; i < number ; i++)
{
MailAddress to = new MailAddress(iMail.to);
MailAddress from = new MailAddress(iMail.from, iMail.displayName);
string body = iMail.body;
string subject = iMail.sub;
oMail = new MailMessage(from, to);
oMail.Subject = subject;
oMail.Body = body;
oMail.IsBodyHtml = true;
oMail.Priority = MailPriority.Normal;
oMail.Sender = from;
s = new SmtpClient(smtpServer);
if (s != null)
{
s.Send(oMail);
}
oMail.Dispose();
s = null;
}
这个循环发送超过 60,000 封电子邮件。但我的问题是,我在某些电子邮件中收到“发送邮件失败”,有时是 5000 次,而其余时间则少于其他邮件。我已经检查了所有这些错误电子邮件是否具有有效的电子邮件地址。不知道是什么问题。我真的需要帮助。
编辑:这是我的异常跟踪
错误 - 发送邮件失败。;内部 Ex - System.IO.IOException:无法从传输连接读取数据:net_io_connectionclosed。在 System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory .ReadLine(SmtpReplyReader caller) at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) 在 System.Net。 Mail.SmtpTransport.SendMail(MailAddress 发件人、MailAddressCollection 收件人、String deliveryNotify、SmtpFailedRecipientException& 异常)