这里是我的代码smtpclient“发送邮件失败”
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;
}
这个循环将超过60000电子邮件。但我的问题是,我在某些电子邮件中发送“发送邮件失败”的次数是5000次,而其他一些邮件的发送次数少了一次。并且我检查了所有这些错误,电子邮件有有效的电子邮件地址。不知道是什么问题。我真的需要帮助。
编辑:这是我的异常跟踪
Error - Failure sending mail.; Inner Ex - System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed. at 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) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
我相信这可以帮助任何人谁也有类似的问题。 http://support.microsoft.com/kb/2183292/en-us – curiousBoy 2013-08-27 18:00:50