有什么办法可以关闭邮件 smtp 会话吗?
我正在使用 Gmail STMP 服务器发送电子邮件。它工作得很好。但几天以来,它有时会停止工作。现在,它只能工作十分之五。
异常:
发送电子邮件失败
内部异常:
无法连接到远程服务器。
与托管技术支持交谈后,他们说他们的服务器上存在邮件会话限制。这是一个“共享主机”,因此当它超过时,所有新连接都会被阻止。他们说他们正在努力解决这个问题。但也表示请检查您是否“正确关闭了邮件会话”。
我查看了它,但没有 Close()
或 Dispose()
。我还读到 SMTP 传输没有确认?
请告诉我是否有办法关闭邮件会话?或者任何解决此问题的解决方法。
我正在使用System.Net.Mail
:
MailMessage msg = new MailMessage();
SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
NetworkCredential info = new NetworkCredential("email", "password");
然后还有另一种方法调用sc.Send()
。
I am using Gmail STMP server to send emails. It works just fine. But since few days, it sometimes stops working. Now, it is only working 5 out of 10 times.
Exception:
Failure Sending Email
Inner Exception:
Unable to connect to remote server.
After talking to hosting technical support, they said there is a mail session limit on their server. This is a "Shared Hosting", so when it exceeds all new connections are blocking. They said they are trying to fix it. But also said please check that you are "closing the mail session properly or not".
I looked into it, but there is no Close()
or Dispose()
. I also read there is no acknowledgement for SMTP tranfer?
Please let me know if there is anyway to close the mail session? Or any workaround to fix this issue.
I am using System.Net.Mail
:
MailMessage msg = new MailMessage();
SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
NetworkCredential info = new NetworkCredential("email", "password");
Then there is another method which calls sc.Send()
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
System.Net.Mail.SmtpClient< /code>
实现了
IDisposable
,所以我建议你使用它。使用使用
块以确保它得到正确处理。请特别注意,不建议使用
System.Web.Mail
,而改用System.Net.Mail
。您正在使用
System.Net.Mail
。在这种情况下,您会发现 SMTPClient 确实有一个Dispose
方法(因为它实现了IDisposable
),它将正常关闭 SMTP 连接。但是,使用using
块被认为是更好的做法,而不是直接调用Dispose
。最后,请注意链接文档中的以下内容:The
System.Net.Mail.SmtpClient
implementsIDisposable
, so I would suggest you use that. Use ausing
block to ensure it gets correctly disposed of.Note particularly that use of
System.Web.Mail
is deprecated in favour ofSystem.Net.Mail
.You are using
System.Net.Mail
. In that case, you will find that the SMTPClient does have aDispose
method (as it implementsIDisposable
), which will gracefully close the SMTP connection. However, it is considered better practice to use ausing
block, rather than callingDispose
directly. Finally, please note the following from the linked documentation: