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#?
For smtp you need to have port number, logon email address and in To:"[email protected];[email protected]" …
Sending emails from C# using an SMTP server requires only a few lines of code: var smtpClient = new SmtpClient("smtp.gmail.com") { Port = 587, Credentials = new NetworkCredential("username", "password"), EnableSsl = true, }; smtpClient. Send("email", "recipient", "subject", "body");
Mailtrap.io represents a cloud-based email testing service with a fake SMTP server under the hood. You send test emails from your app and Mailtrap catches and puts them into a virtual inbox. You can be sure that none of the emails will get to a real user.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With