似乎SmtpClient在处理时抛出IOException。 邮件成功发送,没有错误。 Exeption被代码中的第二个catch块捕获, 应该处理Smtp客户端之后。 邮件已成功发送
public static async Task<String> SendMail(MailMessage mailMessage)
{
String errorString = "";
try
{
using (SmtpClient smtpClient = new SmtpClient(SMTPServer, SMTPPort))
{
smtpClient.EnableSsl = StartTLS;
if (SMTPAuthenticationRequired)
{
NetworkCredential credentials = new NetworkCredential(SMTPUsername, SMTPPassword);
smtpClient.Credentials = credentials;
}
try
{
await smtpClient.SendMailAsync(mailMessage);
}
catch (Exception ex)
{
errorString += ex.Message + ";" + ex.InnerException;
}
}
}
catch (Exception ex) //Exception were catched here...
{
}
return errorString;
}
例外:
"System.IO.IOException" wurde aufgefangen.
HResult=-2146232800
Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Source=System
StackTrace:
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security._SslStream.StartFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.TlsStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Mail.SmtpPooledStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
at System.Net.ConnectionPool.ForceCleanup()
at System.Net.ConnectionPoolManager.CleanupConnectionPool(ServicePoint servicePoint, String groupName)
at System.Net.Mail.SmtpClient.Dispose(Boolean disposing)
at System.Net.Mail.SmtpClient.Dispose()
at Framework.MailTool.SimpleMailTool`2.<SendMail>d__19.MoveNext() in c:\Users\Administrator\Source\Repos\syp-project-api-server2\Framework\MailTool\SimpleMailTool.cs:line 159
InnerException: System.Net.Sockets.SocketException
HResult=-2147467259
Message=An existing connection was forcibly closed by the remote host
Source=System
ErrorCode=10054
NativeErrorCode=10054
StackTrace:
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
InnerException:
我很困惑;-) 请求帮助