錯誤:異常,同時發送電子郵件
System.Mail.SmtpException: System.IO.IOEXCEPTION {"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."}
代碼:
string mailServer = "outlook.domain.com";
SmtpClient client = new SmtpClient(mailServer, 587);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.UseDefaultCredentials = false;
var AuthenticationDetails = new NetworkCredential("[email protected]", "password");
client.Credentials = AuthenticationDetails;
using (MailMessage message = new MailMessage("[email protected]", recipient))
{
message.IsBodyHtml = true;
message.Body = htmlString;
message.Subject = "Test Email";
client.Send(message);
}
閱讀例外情況:「現有連接被遠程主機強制關閉。」。嘗試閱讀以下內容:https://technet.microsoft.com/en-us/library/ms187005%28v=sql.105%29.aspx 將客戶端計算機更新爲服務器版本的SQL Server Native Client。 –
「無法讀取數據」聽起來像指定編碼可以提供幫助。試試'mail.BodyEncoding = Encoding.UTF8;' –