Hi
I am try开发者_JAVA百科ing to sent an email to some addresses i did that using the System.Net.mail the problem is that i need to make the mail message different for each recipient because i need to put a link inside the email that contain the id this user, the problem is the large number of recipient that i cant use a loop to invoke sending function for each usesr like:for (int i=0;i<count;i++)
{moify message(msg);
client.Send(msg);}
thanksYou are sending multiple mails, so I don't believe what you want to achieve is possible. Maybe you can try sending them asynchronously, so you don't have to wait.
the code would be something like this
foreach (var message in messages)
{
var mail = new MailMessage("from", "to");
ThreadPool.QueueUserWorkItem(x => client.Send(mail));
}
I'm not sure if SmtpClient supports sending multiple mails at once, if that's the case you will need to have several SmtpClients and send through the one that is inactive
hope it helps
You can add the recipients directly into your MailMessage like this:
MailMessage message = new MailMessage();
for (int i = 0; i < count; i++)
{
message.To.Add("email");
}
SmtpClient client = new SmtpClient();
client.Send(message);
You can also add the recipients into a single string separating emails with a comma.
Then you can send only one MailMessage.
精彩评论