3
我使用SmtpClient
發送郵件。我使用相同的代碼爲過去2年,但從最後一天,當我發送3個或更多的電子郵件在一起,其中一個將失敗。當我再次發送失敗的郵件時,郵件將發送出去。請幫助我使用aibn.com郵件服務器。SmtpException雖然發送大量3或更多的郵件
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)
它在哪裏失敗?是否有任何異常拋出? – Ofiris
在smtpClient.Send(message); – JIKKU
發送每封郵件後,處理SMTP客戶端可能會解決您的問題。 – Nate