Why can SmtpClient.SendAsync only be called once?

前端 未结 7 1311
暗喜
暗喜 2021-02-02 11:22

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

相关标签:
7条回答
  • 2021-02-02 11:57

    Obviously, this is not an attempt to stop mass mailers.

    The reason is that the SmtpClient class is not thread safe. If you want to send multiple emails simultaneously, you have to spawn a few worker threads (there are a few ways to do that in the .NET Framework) and create separate instances of SmtpClient in each of them.

    0 讨论(0)
提交回复
热议问题