MailMessage 不会发送给超过 2 个收件人?
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需多次调用
Add
即可。Just call
Add
multiple times.MailMessage 的
To
属性是一个集合,因此您应该调用如果要发送到 3 个电子邮件地址,则
message.To.Add
3 次。The
To
property of MailMessage is a collection, so you should callmessage.To.Add
3 times if want to send to 3 email addresses.您应该一次添加一个邮件,而不是将邮件地址合并到单个 Add 语句中:
因为您要添加到一个集合中。
另外,根据我的经验,如果地址相同,该函数通常不会将其添加两次。这可能是 Mailmessage.To.Add 函数的行为,也可能是当我收到通知时 Outlook 已经删除了重复项,但在我看来,它好像过滤掉了重复项。您可能会在您的系统上看到相同的情况。
Instead of contencating mail addressed into a single Add statement, you should be adding them one at a time:
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.
尝试
希望这对
哈维·萨瑟有帮助
Try
Hope this helps
Harvey Sather
我将消息收件人存储在 web.config 文件中,然后像
Harvey Sather一样处理它
I store message recipients in the web.config file and then handle it like this
Harvey Sather