Home > Net >  The process cannot access the file because it is being used by another process (Error occur after nu
The process cannot access the file because it is being used by another process (Error occur after nu

Time:05-29

I have some emails with attachments sending out. Every 56th mail will go error. And the detail of the error is:

System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Mime.SevenBitStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Mime.SevenBitStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.DelegatedStream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Base64Stream.FlushInternal() at System.Net.Base64Stream.Write(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Mime.MimePart.Send(BaseWriter writer) at System.Net.Mime.MimeMultiPart.Send(BaseWriter writer) at System.Net.Mail.Message.Send(BaseWriter writer, Boolean sendEnvelope) at System.Net.Mail.MailMessage.Send(BaseWriter writer, Boolean sendEnvelope) at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message)

I have find some similar answer in google but it is not working. Can anyone help please? I am using .NET 3.5 which could not use SmtpClient.Dispose() Here is the similar question: Dispose method for smtpclient in .net 2.0

CodePudding user response:

Finally I find the answer for my question. It works prefectly for disposing the smtpclient for the previous .net.

Does system.net.mail.smptclient disconnect from the server?

Here is the code

var smtp = new SmtpClient();
smtp.ServicePoint.MaxIdleTime = 1;
smtp.ServicePoint.ConnectionLimit = 1;
smtp.Send(message);
  • Related