Reading between the lines, the problem you're trying to solve is that it's taking too long to send a message, wait for it to finish, then send the next message.
If you use the
SmtpClient.SendMailAsync method[
^], you can start all 150 "send" operations at once, and then wait for them all to complete:
int messagesNeeded = dtNewSMtp.Rows.Count;
List<Task> sendTasks = new(messagesNeeded);
for (int i = 0; i < messagesNeeded; i++)
{
MailMessage mail = new();
mail.To.Add("reciver1@gmail.com");
mail.Subject = "This is a Subject";
mail.Body = "i am a testing body How are you dear may i check you" + i;
mail.IsBodyHtml = true;
mail.From = new(dtNewSMtp.Rows[i][0].ToString(), "CHeck EMail");
messages.Add(mail);
SmtpClient smtp = new("smtp.gmail.com", 587);
smtp.Credentials = new(dtNewSMtp.Rows[i]["Email"].ToString(), dtNewSMtp.Rows[i]["Pwd"].ToString());
smtp.EnableSsl = true;
Task sendTask = smtp.SendMailAsync(mail);
sendTasks.Add(sendTask);
}
Task.WaitAll(sendTasks.ToArray());
NB: As
I said to your colleague yesterday[
^], this sort of code is highly likely to get your email account banned for spamming.