C# 发送大量3封或更多邮件时出现SmtpException
我正在使用C# 发送大量3封或更多邮件时出现SmtpException,c#,smtpclient,C#,Smtpclient,我正在使用SmtpClient发送电子邮件。过去20年我一直使用相同的代码,但从最后一天开始,当我一起发送3封或更多电子邮件时,其中一封将失败。当我再次发送失败的邮件时,它将被发送出去。请帮助我,我正在使用aibn.com邮件服务器 public bool SendMail(string p_strFrom, string p_strDisplayName, string p_strTo, string p_strSubject, string p_strMessage , string st
SmtpClient
发送电子邮件。过去20年我一直使用相同的代码,但从最后一天开始,当我一起发送3封或更多电子邮件时,其中一封将失败。当我再次发送失败的邮件时,它将被发送出去。请帮助我,我正在使用aibn.com邮件服务器
public bool SendMail(string p_strFrom, string p_strDisplayName, string p_strTo, string p_strSubject, string p_strMessage , string strFileName)
{
try
{
p_strDisplayName = _DisplayName;
string smtpserver = _SmtpServer;
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress(_From,_DisplayName);
smtpClient.Host = _SmtpServer;
smtpClient.Port = Convert.ToInt32(_Port);
string strAuth_UserName = _UserName;
string strAuth_Password = _Password;
if (strAuth_UserName != null)
{
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(strAuth_UserName, strAuth_Password);
smtpClient.UseDefaultCredentials = false;
if (_SSL)
{
smtpClient.EnableSsl = true;
}
smtpClient.Credentials = SMTPUserInfo;
}
message.From = fromAddress;
message.Subject = p_strSubject;
message.IsBodyHtml = true;
message.Body = p_strMessage;
message.To.Add(p_strTo);
try
{
smtpClient.Send(message);
Log.WriteSpecialLog("smtpClient mail sending first try success", "");
}
catch (Exception ee)
{
Log.WriteSpecialLog("smtpClient mail sending first try Failed : " + ee.ToString(), "");
return false;
}
return true;
}
catch (Exception ex)
{
Log.WriteLog("smtpClient mail sending overall failed : " + ex.ToString());
return false;
}
}
收到以下错误消息
smtpClient mail sending Failed :
System.Net.Mail.SmtpException:
Failure sending mail.
System.NullReferenceException:
Object reference not set to an instance of an object.
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of Inner Exception Stack Trace ---
at System.Net.Mail.SmtpClient.Send(MailMessage message)
我已经更改了邮件服务器,现在它工作正常。这可能取决于某些邮件服务限制,以防止泛滥和/或垃圾邮件。它在哪里失败?smtpClient.Send(message)是否有任何异常抛出;也许在您发送每封邮件后处理SMTP客户端可以解决您的问题。好的,谢谢您的建议。但为什么它在过去两年中运行良好。请提供更多想法查看SmtpException的详细信息。它有什么价值?