Sending SMTP e-mail at a high rate in .NET

Posted by Martin Liversage on Stack Overflow See other posts from Stack Overflow or by Martin Liversage
Published on 2010-04-26T13:27:22Z Indexed on 2010/04/27 14:43 UTC
Read the original article Hit count: 262

Filed under:
|
|

I have a .NET service that processes a queue on a background thread and from the items in the queue sends out a large number of small e-mail messages at a very high rate (say 100 messages per second if that is even possible). Currently, I use SmtpClient.Send() but I'm afraid that it may hamper performance.

Each call to Send() goes through a full cycle of opening the socket, performing the SMTP conversation (HELO, MAIL FROM, RCPT TO, DATA) and closing the socket. In pseudo code:

for each message {
  open socket
  send HELO
  send MAIL FROM
  send RCPT TO
  send DATA
  close socket
}

I would think that the following pseudo code would be more optimal:

open socket
send HELO
for each message {
  send MAIL FROM
  send RCPT TO
  send DATA
}
send QUIT
close socket

Should I be concerned about the performance of SmtpClient.Send() when sending e-mail at a high rate? What are my options for optimizing the performance?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about smtp