发送到多个电子邮件地址但仅显示一个 C#

发布于 2024-09-09 02:29:43 字数 266 浏览 6 评论 0原文

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

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

Bob Hope; Brain Cant; Roger Rabbit;Etc Etc

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鯉魚旗 2024-09-16 02:29:43

听说过 BCC(密件抄送)吗? :)

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

MailMessage 类中似乎有一个密件抄送项

http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage。

http://msdn.aspx microsoft.com/en-us/library/system.net.mail.mailmessage.bcc.aspx

这是我从 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() );
          }
        }

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() );
          }
        }
幻梦 2024-09-16 02:29:43

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

MailMessage message = new MailMessage();
MailAddress bcc = new MailAddress("[email protected]"); 

// Add your email address to BCC
message.Bcc.Add(bcc);

If you are using the MailMessage class, make use of the BCC (Blind Carbon Copy) property.

MailMessage message = new MailMessage();
MailAddress bcc = new MailAddress("[email protected]"); 

// Add your email address to BCC
message.Bcc.Add(bcc);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文