8

I have to send email from all SMTP senders

 2 years ago
source link: https://www.codeproject.com/Questions/5332332/I-have-to-send-email-from-all-SMTP-senders
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

See more:

I have Multiple Smtp Senders , i just want to send Emails from all senders in One Shot, i ahve all SMtp in Datatable, adding all smtps in SmtpClient Which is ListType,and adding all reciver in another list which is MailMessage TYpe.All is going smoothly only i just want to send All Emails In One Shot ,without For Loop.
Or can we do this in SqlServer, Any help would be life Saver,Thx in advance

What I have tried:

Hi here i am adding SMTP also in the list but , i need to call it inside for loop to send, so means if i have 150 SMTp , i need to call (SMTP.send) 150 times and it will take too much of time , please Review this code

public void SendEmailFromAllSender()
{
DataTable dtNewSMtp = new DataTable();
// aRandom = Get16DigitRandom();
DataRow dr;
dtNewSMtp.Columns.AddRange(new DataColumn[2] { new DataColumn("Email"), new DataColumn("Pwd") });

dr = dtNewSMtp.NewRow();
dr[0] = "[email protected]";
dr[1] = "password1";
dtNewSMtp.Rows.Add(dr);

dr = dtNewSMtp.NewRow();
dr[0] = "[email protected]";
dr[1] = "password2";
dtNewSMtp.Rows.Add(dr);

int messagesNeeded = dtNewSMtp.Rows.Count;
List<mailmessage> messages = new List<mailmessage>(messagesNeeded);
List<smtpclient> SMTpClients = new List<smtpclient>(messagesNeeded);

for (int i = 0; i < messagesNeeded; i++)
{
MailMessage mail = new MailMessage();
mail.To.Add("[email protected]");
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 System.Net.Mail.MailAddress(dtNewSMtp.Rows[i][0].ToString(), "CHeck EMail");
messages.Add(mail);

SmtpClient NewSmtp = new SmtpClient("smtp.gmail.com", 587);
NewSmtp.Credentials = new NetworkCredential(dtNewSMtp.Rows[i]["Email"].ToString(), dtNewSMtp.Rows[i]["Pwd"].ToString());
NewSmtp.EnableSsl = true;
SMTpClients.Add(NewSmtp);

}

for (int k = 0; k < messagesNeeded; k++)
{
SMTpClients[k].Send(messages[k]);// Please Tell me here how i can send all emails in one shot without the loop
}

}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK