发送到多个电子邮件地址,但仅显示一个C# [英] Sending to multiple Email addresses but displaying only one C#
问题描述
我正在C#中使用SmtpClient,我将发送到可能有数百个电子邮件地址.我不想遍历每个人并向他们发送一封单独的电子邮件.
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.
我知道只能发送一次消息,但我不希望该地址的电子邮件显示其他100个这样的电子邮件地址:
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?
推荐答案
有没有听说过BCC(盲抄本)? :)
Ever heard of BCC (Blind Carbon Copy) ? :)
如果您可以确保SMTP客户端可以将地址添加为密件抄送,那么您的问题将得到解决:)
If you can make sure that your SMTP Client can add the addresses as BCC, then your problem will be solved :)
MailMessage类中似乎有一个密件抄送项目
There seems to be a Blind Carbon Copy item in the MailMessage class
http://msdn.microsoft.com/zh-cn/library/system.net.mail.mailmessage.aspx
http://msdn.microsoft. com/en-us/library/system.net.mail.mailmessage.bcc.aspx
这是我从MSDN获得的样本
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() );
}
}
这篇关于发送到多个电子邮件地址,但仅显示一个C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!