MailMessage 不会发送给超过 2 个收件人?

发布于 2024-12-15 08:26:54 字数 621 浏览 3 评论 0原文

在 ASP.NET 中,我正在发送 MailMessage,但它不会通过。我使用的代码是

message.To.Add(email1 + ", " + email2 + ", " + email3);

当我这样做时,我从未收到我的邮件。但是,如果我使用这段代码:

message.To.Add(email1 + ", " + email2);

它每次都发送得很好。有人知道这是怎么回事吗?所有 3 封电子邮件都是相同的(用于测试目的),并且在调试时已验证正确。我尝试为第三个插入不同的电子邮件地址,但仍然没有任何结果。我可能错过了一些明显的东西......

编辑: 每个人都告诉我单独添加它们,如果每个人都同意的话,这可能是个好建议。我之前没有这样做的原因是我只是用三个单独的地址再次尝试,但没有一个地址被发送。如果这应该有效的话,也许我完全有另一个问题?

编辑:对于将来遇到同样问题的任何人,这就是我所做的。创建 MailMessage 时,我没有使用任何参数创建它,而是单独指定 From 参数。我将“发件人”和所有“收件人”电子邮件封装在 new MailAddress() 中,所有这些更改的组合似乎都有效。

In ASP.NET I am sending a MailMessage but it won't go through. The code I am using is

message.To.Add(email1 + ", " + email2 + ", " + email3);

When I do this I never receive my mail. However if I use this code:

message.To.Add(email1 + ", " + email2);

It sends just fine every time. Anybody know what is going on here? All 3 emails are the same (for testing purposes) and have been verified to be correct while debugging. I tried inserting a different email address for the third and still nothing went through. I may be missing something obvious...

EDIT:
Everyone is telling me to add them individually which may well be good advice if everyone agrees upon it. The reason I didn't do this previously and I just tried it again with three seperate addresses and none of them were sent. Maybe I have another issue entirely if that is supposed to work?

EDIT: For anyone with the same problem in the future here is what I did. When creating the MailMessage I didn't create it with any parameters and instead specified the From parameter seperately. I wrapped the From and all To emails in new MailAddress() and the combination of all those changes appeared to work.

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

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

发布评论

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

评论(5

过气美图社 2024-12-22 08:26:54

只需多次调用 Add 即可。

Just call Add multiple times.

时光匆匆的小流年 2024-12-22 08:26:54

MailMessage 的 To 属性是一个集合,因此您应该调用
如果要发送到 3 个电子邮件地址,则 message.To.Add 3 次。

The To property of MailMessage is a collection, so you should call
message.To.Add 3 times if want to send to 3 email addresses.

娇俏 2024-12-22 08:26:54

您应该一次添加一个邮件,而不是将邮件地址合并到单个 Add 语句中:

message.To.Add(email1);
message.To.Add(email2);
message.To.Add(email3);

因为您要添加到一个集合中。

另外,根据我的经验,如果地址相同,该函数通常不会将其添加两次。这可能是 Mailmessage.To.Add 函数的行为,也可能是当我收到通知时 Outlook 已经删除了重复项,但在我看来,它好像过滤掉了重复项。您可能会在您的系统上看到相同的情况。

Instead of contencating mail addressed into a single Add statement, you should be adding them one at a time:

message.To.Add(email1);
message.To.Add(email2);
message.To.Add(email3);

Since you're adding to a collection.

Also, if the addresses are the same, the function usually doesn't add it twice in my experience. This may be a behavior of the Mailmessage.To.Add function, or it could be that when it gets to me Outlook has stripped out duplicates, but it looks to me like it filters out duplicates. You may be seeing the same on your system.

新人笑 2024-12-22 08:26:54

尝试

message.to.add(email1);
message.to.add(email2);
message.to.add(email3);
message.to.add(email4);

希望这对

哈维·萨瑟有帮助

Try

message.to.add(email1);
message.to.add(email2);
message.to.add(email3);
message.to.add(email4);

Hope this helps

Harvey Sather

感性不性感 2024-12-22 08:26:54

我将消息收件人存储在 web.config 文件中,然后像

 string lstrDistributitionList = ConfigurationSettings.AppSettings["SMTP_DISTRIBUTION_LIST"];
                    string[] lastrDistributitionList = lstrDistributitionList.Split(';');

                    for (Int32 loopCounter = 0; loopCounter < lastrDistributitionList.Length; loopCounter++)
                    {
                        msg.To.Add(lastrDistributitionList[loopCounter]);
                    }

Harvey Sather一样处理它

I store message recipients in the web.config file and then handle it like this

 string lstrDistributitionList = ConfigurationSettings.AppSettings["SMTP_DISTRIBUTION_LIST"];
                    string[] lastrDistributitionList = lstrDistributitionList.Split(';');

                    for (Int32 loopCounter = 0; loopCounter < lastrDistributitionList.Length; loopCounter++)
                    {
                        msg.To.Add(lastrDistributitionList[loopCounter]);
                    }

Harvey Sather

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