1

I'm using this piece of code to send a mail:

SmtpClient client = new SmtpClient();
client.Host = smtpServer;
client.Send(mailMessage);

If I trigger this code ten times/second, then after some hundred mails, sending a mail takes 10 seconds... Could there be a queue involved here?

5

Looks like the mail server is forcing this delay, probably in order to avoid spam: http://en.wikipedia.org/wiki/Tarpit_(networking).

What mail server are you using? How is it configured? Are you using authenticated or unauthenticated SMTP to send mails?

  • 1
    Either a delay from the server, ot it is overloaded - depends how the SMTP server looks. I remember "killing" a company exchange by doing what I Was asked for - submitting 50.000 emails as fast as possible ;) – TomTom Apr 18 '10 at 13:40
1

As Massimo said, many smart SMTP servers have a throttle capability. It could also be limited external to the SMTP server using network throttling.

If your code is blocking, you should send this asynchronously. You can either use the .SendAsync() method on the SmtpClient, which is not my favorite, or using something like SmartThreadPool to create a thread for each message.

If you're sending these asynchronously, you will not be able to enclose the message in a using() statement, so you will need to call .Dispose() on the MailMessage, or there will be resource issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.