Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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?

share|improve this answer
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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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