问题
I am quite a newbie in C# but I have learnt a lot from VB.Net about programming in .Net for windows.
I have just made a simple SMTP client which sends emails from the program. It is a console application and can only send one email through the server at a time. This is very slow and I need to send multiple emails through my client at the same time.
Is this possible in C#?
回答1:
simply use multiple threads (multiple processes).
In C# you can do this with a Task.
new Task(delegate {
smtpClient.send(myMessage);
}).Start();
Just wrap your send
command in this object and it will be send Asynchronously.
Be careful if this is wrapped in a loop it will start a new process for each mail.
if you need to send large amounts of mails at the same time I suggest you use a ThreadPool
. It lets you control how many concurent threads you'd like to have at the same time.
来源:https://stackoverflow.com/questions/20747498/speed-up-sending-multiple-emails-through-smtp-server-using-system-net-mail