views:

42

answers:

2

I'm using MailMessage class and then sent mail to many recipients. My code is here.

MailMessage msg = new MailMessage();

SmtpClient client = new SmtpClient("smtp.mysite.com");
client.EnableSsl = false;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("[email protected]", "mypassword");
forea(User u in users)
{
  msg.To.Add(u.Email);
}

client.Send(msg);

This work successfully.

But problem is all email shown on the recipient computer. TO: user1.fds.com;email2.fdsa.com;email3.fdsa.com;... etc.

I need to show only current user email. How to do it?

Maybe i will do it like this

forea(User u in users)
{
  msg.To.Clear();
  msg.To.Add(u.Email);
  client.Send(msg);
}

But it is too slowly.

+2  A: 

One option is to use MailMessage.Bcc instead of To. That won't show the recipient in the "To" line of course, but usually that's not a problem.

I do hope the "many recipients" genuinely want this mail...

Jon Skeet
+2  A: 

I would suggest that you iterate over the list of recipients and send the emails one at a time.

Using BCC may cause the mail to be classed as spam.

Barry
+1 and would be fine: users.ConvertAll(u => new MailMessage(u.Email)).ForEach(client.Send)
onof