在 C# 中使用 BCC 不带 TO 通过 SMTP 发送邮件

发布于 2024-07-09 07:08:30 字数 420 浏览 10 评论 0原文

我正在尝试使用 C# 中的 System.Net.Mail.MailMessage 类创建一封电子邮件,该电子邮件全部通过密件抄送发送到电子邮件地址列表。 我不想包含 TO 地址,但似乎我必须包含,因为如果我在 中对 TO 地址使用空字符串,则会出现异常MailMessage 构造函数。 该错误指出:

ArgumentException
The parameter 'addresses' cannot be an empty string.
Parameter name: addresses

当然可以仅使用 BCC 发送电子邮件,因为这不是 SMTP 的限制。

有办法解决这个问题吗?

I am trying to use the System.Net.Mail.MailMessage class in C# to create an email that is sent to a list of email addresses all via BCC. I do not want to include a TO address, but it seems that I must because I get an exception if I use an empty string for the TO address in the MailMessage constructor. The error states:

ArgumentException
The parameter 'addresses' cannot be an empty string.
Parameter name: addresses

Surely it is possible to send an email using only BCC as this is not a limitation of SMTP.

Is there a way around this?

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

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

发布评论

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

评论(8

旧瑾黎汐 2024-07-16 07:08:30

我认为如果您注释掉整个 emailMessage.To.Add(sendTo); 行,它将发送 To 字段为空的电子邮件。

I think if you comment out the whole emailMessage.To.Add(sendTo); line , it will send the email with To field empty.

浅听莫相离 2024-07-16 07:08:30

对内部邮件群发执行同样的操作,您不希望人们一直回复所有人。

将其发送给您自己(或虚拟帐户),然后添加您的密件抄送列表。

Do the same thing you do for internal mail blasts where you don't want people to reply-to-all all the time.

Send it to yourself (or a dummy account), then add your BCC list.

白衬杉格子梦 2024-07-16 07:08:30

它甚至不需要是真实的电子邮件地址,我通常使用 [email protected] 表示 TONoReply@CompanyName 表示 FROM

It doesn't even need to be a real e-mail address, I typically use [email protected] for TO, and NoReply@CompanyName for FROM.

夜司空 2024-07-16 07:08:30

您必须包含一个 TO 地址。 只需将其发送到您不介意接收邮件的“垃圾”电子邮件地址即可。

You have to include a TO address. Just send it to a "junk" email address that you don't mind getting mail on.

梦途 2024-07-16 07:08:30

只是不要在 To 属性上调用 Add-方法。

Just don't call the Add-method on the To-property.

复古式 2024-07-16 07:08:30

必须有一个地址。 自从 80 年代最初的 sendmail 实现以来一直都是这种方式,据我所知,所有 SMTP 邮件程序都有相同的要求。 您可以只使用一个虚拟地址。

Must have a to address. It has been this way since the original sendmail an implementations in the 80s and all SMTP mailers, I know of, have the same requirement. You can just use a dummy address for to.

顾冷 2024-07-16 07:08:30

您可以使用临时假地址,然后立即将其删除:

MailMessage msg = new MailMessage(from, "[email protected]");
msg.To.Clear();
foreach (string email in bcc.Split(';').Select(x => x.Trim()).Where(x => x != ""))
{
     msg.Bcc.Add(email);
}

You can use a temporary fake address then remove it just after:

MailMessage msg = new MailMessage(from, "[email protected]");
msg.To.Clear();
foreach (string email in bcc.Split(';').Select(x => x.Trim()).Where(x => x != ""))
{
     msg.Bcc.Add(email);
}
雨后彩虹 2024-07-16 07:08:30

我认为您正在尝试做类似的事情:

var msg = new MailMessage("[email protected]", "");

这就是您看到错误消息的原因。

相反,尝试这样的事情:

MailMessage msg = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.notreal.com");
msg.From = new MailAddress("[email protected]");
//msg.To.Add("[email protected]"); <--not needed
msg.Bcc.Add("[email protected]");

I think you were trying to do something like :

var msg = new MailMessage("[email protected]", "");

That's why you were seeing the error message.

Instead, try something like this:

MailMessage msg = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.notreal.com");
msg.From = new MailAddress("[email protected]");
//msg.To.Add("[email protected]"); <--not needed
msg.Bcc.Add("[email protected]");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文