Sending to multiple Email addresses but displaying only one C#
I am using the SmtpClient in C# and I will be 开发者_运维百科sending to potentially 100s of email addresses. I don't want to have to loop through each one and send them an individual email.
I know it is possible to only send the message once but I don't want the email from address to display the 100s of other email addresses like this:
Bob Hope; Brain Cant; Roger Rabbit;Etc Etc
Is it possible to send the message once and ensure that only the recipient's email address is displayed in the from part of the email?
Ever heard of BCC (Blind Carbon Copy) ? :)
If you can make sure that your SMTP Client can add the addresses as BCC, then your problem will be solved :)
There seems to be a Blind Carbon Copy item in the MailMessage class
http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx
http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.bcc.aspx
Here is a sample i got from MSDN
public static void CreateBccTestMessage(string server)
{
MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");
MailAddress to = new MailAddress("jane@contoso.com", "Jane Clayton");
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the SmtpClient class.";
message.Body = @"Using this feature, you can send an e-mail message from an application very easily.";
MailAddress bcc = new MailAddress("manager1@contoso.com");
//This is what you need
message.Bcc.Add(bcc);
SmtpClient client = new SmtpClient(server);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
Console.WriteLine("Sending an e-mail message to {0} and {1}.",
to.DisplayName, message.Bcc.ToString());
try {
client.Send(message);
}
catch (Exception ex) {
Console.WriteLine("Exception caught in CreateBccTestMessage(): {0}",
ex.ToString() );
}
}
If you are using the MailMessage class, make use of the BCC (Blind Carbon Copy) property.
MailMessage message = new MailMessage();
MailAddress bcc = new MailAddress("manager1@contoso.com");
// Add your email address to BCC
message.Bcc.Add(bcc);
精彩评论