为什么SmtpClient.SendAsync只能被调用一次? [英] Why can SmtpClient.SendAsync only be called once?

查看:261
本文介绍了为什么SmtpClient.SendAsync只能被调用一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SmtpClient在.NET中编写通知服务(出于完全合法的非垃圾邮件目的).最初,我只是循环浏览每条消息并发送,但是这很慢,我想提高速度.因此,我切换为使用"SendAsync",但现在在第二次调用时收到以下错误:

I'm trying to write a notification service (for completely legit non-spam purposes) in .NET using SmtpClient. Initially I just looped through each message and sent it, however this is slow and I would like to improve the speed. So, I switched to using 'SendAsync', but now get the following error on the second call:

An asynchronous call is already in progress. 

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

I read this to mean that MS crippled System.Net.Mail to prevent mass-mailers. Is this correct? If so, is there a better way to do this in .NET, and still be able to log the results of each email(which is important to our client). If not, why can SendAsync only be called once?

推荐答案

根据文档:

调用SendAsync后,您必须等待 用于将电子邮件传输到 尝试发送之前完成 使用发送或的另一封电子邮件 SendAsync.

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实例.

So to send multiple mails at the same time you need multiple SmtpClient instances.

这篇关于为什么SmtpClient.SendAsync只能被调用一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆