Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 587
dagda1 Avatar asked Jul 10 '10 16:07

dagda1


1 Answers

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("[email protected]", "Ben Miller");
            MailAddress to = new MailAddress("[email protected]", "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("[email protected]");

                //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() );
          }
        }
like image 63
Ranhiru Jude Cooray Avatar answered Oct 13 '22 12:10

Ranhiru Jude Cooray