I’m trying to find a .Net equivalent of the java code in this question: How to send multiple emails in one session? Amazingly, this question hasn’t been answered yet on Stack Overflow (or I’m not searching with the right terms.)
I want to be able to connect to my SMTP server (this is a 3rd party server, not under my control) and send up to 500 emails or so at one time. These emails are requested by our users, and are all unique. I know I could loop through a list and send them sequentially, or even use threading to spawn multiple processes, but this seems to be wasteful. I’d be opening a connection, sending one email, then closing the connection.
I’ve seen it implied that .Net will cache an SMTP connection, kind of like database connection pooling, but I can’t find confirmation. Plus I’d be relying on code that may have unintended side effects for the SMTP that I’m using.
Has anyone done this in .Net? Did you use a 3rd party component? Did you instead just manually implement the SMTP RFC? I really don’t want to have to do that.
You can create a SMTP object with
SMTPClient
so create on of those and then call the
Sendmethod for each email you need to send.You can’t really send all those mails at ‘once’ but you can send them without recreating the SMTP object.