Link to home
Start Free TrialLog in
Avatar of dingir
dingirFlag for Sweden

asked on

How to avoid: Net.Mail.SmtpException IO Exception errors

I use a script thet sends ten thousends of mail. I've got a strange error that occurs every 2 minutes and 40 seconds (more or less exactly). 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.Mail.SmtpClient.Send(Mailmsg msg)    
 at ....SmtpSend(......) in ...Message.cs:line 127

I create a smtpclient with smtpclient client = new smtpclient(), then I put the client.Send(msg) itself in a try catch. That catch gives me the error description... until then the script was stopped after this.. now the catch are hooking it up and continue the script.. but how do I avoid this?

Seems to me like a bufffer that can't take all data because any garbage collection that does not work enough well.. ?!
Avatar of Avodah
Avodah
Flag of United Kingdom of Great Britain and Northern Ireland image

You should pause sending the emails after either:

1. Sending a set number of email in a specific timeframe
2. Delay thread for a few milliseconds after sending each email  - Thread.Sleep(50)

DaTribe
Avatar of dingir

ASKER

Thank's! That may do it? Are yu possible to provide me with a code sample that run a thread for example 500 loops and paus 3 seconds, then continue running?

As the functions is today, they create a thread with

Threading.Thread t = new threading.thread()
t.start(function)

that's it
ASKER CERTIFIED SOLUTION
Avatar of Avodah
Avodah
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dingir

ASKER

thank's a lot.. i will check it up.. :)