This code below will work fine for you:
public static void SendBulkMail(Shooter sender, List<string> receiversList, string mailtext)
{
MailMessage email = new MailMessage();
email.From = new MailAddress(sender.Mailaddress, string.Format("{0}, {1}", sender.Lastname, sender.Surname));
foreach (string receiver in receiversList)
{
email.Bcc.Add(new MailAddress(receiver));
}
email.Subject = string.Format("SMGT BulkMail von {0} {1}", sender.Lastname, sender.Surname);
email.IsBodyHtml = false;
email.Body = string.Format("{0}\n\n\n--> Diese Email-Nachricht wurde als BulkMail vom SMGT Web-Portal gesendet. Absender ist {1} {2} ({3} - {4})\n\nDa es sich um ein BulkMail handelt sind alle Empfänger im BCC-Feld aufgeführt",
mailtext, sender.Lastname, sender.Surname, sender.HomeShootingClub.Name, sender.HomeShootingClub.City);
SmtpClient client = ConnectSmtpClient();
client.Send(email);
}
private static SmtpClient ConnectSmtpClient()
{
SmtpClient client = new SmtpClient();
client.Port = 587;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("someone@gmail.com", "password");
client.Host = "smtp.gmail.com";
return client;
}
Shooter is a class to represent a person.
cheers,
Marco Bertschi