发送邮件时遇到的一些问题
我有以下类:
public class Email
{
public System.Net.Mail.SmtpClient SmtpClient
{
get
{
if (_client == null)
{
_client = new System.Net.Mail.SmtpClient();
}
return _client;
}
}
}
并使用它
static Email email = new Email();
(在方法中)
email.SmtpClient.Send(message);
,在调用此代码后我得到异常:
服务不可用,正在关闭传输通道。服务器 响应为:4.4.2 服务超时。
为什么?
I have the following class:
public class Email
{
public System.Net.Mail.SmtpClient SmtpClient
{
get
{
if (_client == null)
{
_client = new System.Net.Mail.SmtpClient();
}
return _client;
}
}
}
and use it
static Email email = new Email();
(in method)
email.SmtpClient.Send(message);
and after some calls of this code I get exception:
Service not available, closing transmission channel. The server
response was: 4.4.2 service timed out.
why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此错误可能是因为您超出了
MessageRateLimitExceeded
(这限制了您发送多条消息的速度)或连接已断开。SMTP 服务器上还有其他配置参数,可以限制每个会话可以发送的数据量。 SmtpClient 还管理池中的连接,
所以我认为最好在发送几条消息后创建一个新客户端。您还必须处置客户端以确保客户端向服务器发送 QUIT 消息。
有关错误情况的详细信息,请阅读此 MSDN 文章。
This error can be because you exceed the
MessageRateLimitExceeded
(which limits how fast you can send multiple messages) or the connection has dropped.There is also other configuration parameters on SMTP servers which can limit how many and how much data you can send per session. The SmtpClient also manage connections in a pool,
so I think it's better to create a new client after you have sent few messages. You must also Dispose the client to ensure the client sends a QUIT message to servers.
For more information about error situations, read this MSDN Article.