+2 votes

When sending a group of smtp messages I got an error after it had sent around 24. It looked like a timeout error and I was wondering when I issue a smtp.Connect("Servername", 25) command does this have a timeout associated with it. Now I open and close connection for each e-mail and it works fine but I suspect this is less efficient.

As an aside I tend to not like re-declaring objects every time I use one and in the MailBuilder I can clear the to and cc address but not the attachments, is there a way to do this?

by

1 Answer

+1 vote

Creating new SMTP connection for each email is inefficient. Tracking what you sent and what is left is much wiser solution. You just need to catch all exceptions and simply retry.

By default, timeout values are set to 20 seconds. You can use SendTimeout and ReceiveTimout properties to change this value.

This value only affects single read/write to the network stream. Every command (or even every byte written/read) resets this value. Sending email takes at least 3 commands to complete.

I tend to not like re-declaring objects every time

There is no way to clear MailBuilder's attachments. Creating new object in .NET is really fast. You shouldn't worry about that.

by (297k points)
Thanks for your quick response, I love the fact that I can save to an eml file when I send an e-mail and I don't have to send a bcc to a mail box for archive purposes and deal with all the issues that can cause like bounces when it is full etc.
...