如何最好地管理SMTP客户端 [英] How to best manage SMTP clients

查看:412
本文介绍了如何最好地管理SMTP客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于SmptClient的MSDN文档说,不能保证实例成员是线程安全的(通过使用实例属性将MailWriter之类的内容存储在

The MSDN docs for SmptClient say that instance members are not guaranteed to be thread-safe (born out by the use of instance properties to store things like the MailWriter in the reference source).

另一方面,这篇文章(根据我的经验)表明,仅为发送的每封电子邮件创建和处置SmtpClient都会使您很容易达到连接限制.

On the other hand, this post (and my experience) suggests that simply creating and disposing an SmtpClient for each email sent can cause you to hit the connection limit pretty easily.

管理这些对象的最佳方法是什么?我是否必须使用信号量手动创建池或限制使用量?或者,是否有一些更容易遵循的模式.我一直在使用相同的邮件服务器.

What's the best way to manage these objects? Do I have to manually create a pool or throttle usage with a semaphore? Or, is there some easier pattern to follow. I'm always using the same mail server.

推荐答案

不要重新发明现有的工具.查看 SmtpClient 类的 DeliveryMethod 属性.一种选择是让邮件自动为您排队,并通过 Microsoft SMTP Service 在后台传递.将DeliveryMethod设置为 PickupDirectoryFromIis ,消息将以生成时的最快速度写入队列邮件文件夹.然后,您要做的就是将Microsoft SMTP服务器配置为将传出邮件转发到本地邮件服务器,然后就完成了.如果使用邮件提取选项查找对较旧的CDOSYS方法的引用,则其工作方式完全相同.

Don't reinvent the tools that you already have available. Look at the DeliveryMethod property for the SmtpClient class. One of the options is to have the messages automatically queue up for you and delivered in the background via the Microsoft SMTP Service. Set the DeliveryMethod to PickupDirectoryFromIis and the messages will be written to the queue mail folder as fast as you can generate them. Then all you have to do is configure the Microsoft SMTP Server to forward the outgoing mail to a local mail server and you are done. If you look for references to the older CDOSYS methods using the mail pickup option, this works exactly the same way.

这篇关于如何最好地管理SMTP客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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