c# - 为什么 SmtpClient.SendAsync 只能调用一次?

标签 c# smtpclient system.net.mail

我正在尝试使用 SmtpClient 在 .NET 中编写一个通知服务(为了完全合法的非垃圾邮件目的)。最初我只是遍历每条消息并发送它,但是这很慢,我想提高速度。因此,我改用“SendAsync”,但现在在第二次调用时出现以下错误:

An asynchronous call is already in progress. 

我读到这意味着 MS 削弱了 System.Net.Mail 以防止群发邮件。这个对吗?如果是这样,是否有更好的方法在 .NET 中执行此操作,并且仍然能够记录每封电子邮件的结果(这对我们的客户很重要)。如果不是,为什么 SendAsync 只能调用一次?

最佳答案

根据documentation :

After calling SendAsync, you must wait for the e-mail transmission to complete before attempting to send another e-mail message using Send or SendAsync.

所以要同时发送多封邮件你需要多个 SmtpClient 实例。

关于c# - 为什么 SmtpClient.SendAsync 只能调用一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/389709/

相关文章:

c# - WP7-对网络通信、跨线程访问和连续传递感到困惑

c# - 将用户名/密码传递给 SmtpClient (.NET) 的正确方法

java - 从 Javamail 中的 smtp 服务器获取 SSL 版本

asp.net - 使用 System.Net.Mail 处理 Global.cs 错误

c# - 从 jQuery 对话框按钮事件中单击 ASP.NET 按钮

c# - 使用 AutoFac 的 MVC Controller 通用注入(inject)

c# - 如何在 .net 3.5 中发送带有返回路径的电子邮件

c# - 参数 'addresses'不能为空串

c# - 我可以重复使用 Tridion 附带的 SOLR 实例吗?

smtpclient - System.Net.Mail.SmtpClient.Send 是同步的吗?