6

我在 C# 中使用 SmtpClient,我将发送到潜在的 100 个电子邮件地址。我不想遍历每一个并向他们发送单独的电子邮件。

我知道可以只发送一次消息,但我不希望来自地址的电子邮件显示 100 个其他电子邮件地址,如下所示:

Bob Hope; Brain Cant; Roger Rabbit;Etc Etc

是否可以一次发送消息并确保仅收件人的电子邮件地址显示在电子邮件发件人部分?

4

2 回答 2

12

听说过 BCC(盲抄本)吗?:)

如果您可以确保您的 SMTP 客户端可以将地址添加为密件抄送,那么您的问题将得到解决 :)

MailMessage 类中似乎有一个 Blind Carbon Copy 项

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

这是我从 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() );
          }
        }
于 2010-07-10T16:26:09.573 回答
3

如果您使用 MailMessage 类,请使用密件抄送(Blind Carbon Copy)属性。

MailMessage message = new MailMessage();
MailAddress bcc = new MailAddress("manager1@contoso.com"); 

// Add your email address to BCC
message.Bcc.Add(bcc);
于 2010-07-10T16:33:26.017 回答