In my current WPF project I built in a button, which sends emails to all elements in an array (these elements are persons, which all have an email address referring to).
I use System.Net.Mail
for this.
Now, the problem is that it takes the button very long to send all these emails, even with one email sent it takes about a second to send. So the program is for this certain time not usable, you have to wait until all emails have been sent. This interrupts everything of course and is not wished.
Is there a way to accelerate this process?
This is my used code for sending the email:
string[] myArray = myList.ToArray();
foreach (string str in myArray)
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("myMail@Adress.com", "myEmailName");
mail.To.Add(targetEmailAdress);
mail.Subject ="mySubject";
mail.IsBodyHtml = true;
string htmlBody;
htmlBody =
"<html> " +
"<body>" +
"<p>MyText123</p>" +
"</body> " +
"</html>";
mail.Body = htmlBody;
SmtpServer.Port = myPort;
SmtpServer.Credentials = new System.Net.NetworkCredential("myMail@Adress.com", @"myPassword");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
}