发送邮件失败。无法将数据写入传输连接
我正在使用 Gmail SMTP 服务器从 VB.Net 发送邮件。尽管它可以正常发送一些电子邮件,但对于其他一些电子邮件,它会返回以下错误:
发送邮件失败。无法将数据写入传输连接 System.Net.Sockets.SocketException:主机中的软件中止了已建立的连接
I am using a Gmail SMTP server to send mail from VB.Net. Although it sends some emails fine, for some others it returns the following error:
Failure sending mail. Unable to write data to the transport connection System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最近,我在使用带有 350k 附件的电子邮件时重复使用
SmtpClient.SendMail(MailMessage)
时遇到了同样的问题。每第 33 条消息,就会出现您给出的错误。事实证明,当消息发送完成时,封装 SendMail 功能的共享组件没有调用
SmtpClient
类上的Dispose()
。将
client.Dispose()
添加到 SmtpClient 实例立即解决了问题,现在消息发送没有问题 - 数百条消息(是的,它们是给我们客户的合法产品通知,而不是垃圾邮件); )I was experiencing this same issue recently with
SmtpClient.SendMail(MailMessage)
being used repeatedly with an email with a 350k attachment. Every 33rd message, the error you gave would occur.Turns out our shared component which encapsulated the SendMail functionality was not calling
Dispose()
on theSmtpClient
class when the message was finished sending.Adding
client.Dispose()
to the SmtpClient instance cleared the problem right up and now messages go out no problem - hundreds of them (and yes they're legitimate product notifications to our customers, not spam) ;)根据我在网上看到的信息,与此异常相关的Winsock错误代码是WSAECONNABORTED。
您可以在以下地址阅读更多相关内容以获取解释: WSAECONNABORTED
基本上这意味着当您的应用程序尝试发送大电子邮件时,服务器关闭了连接。
也许您应该检查 Gmail 文档,看看它是否对邮件大小或发送的邮件总数有一些限制。看来您在套接字上传输了太多数据。
From what I read on the net, the Winsock error code associated with this exception is WSAECONNABORTED.
You can read more about it at this address for an explanation: WSAECONNABORTED
Basically it means that the server closed the connection while your application was trying to send a large e-mail.
Maybe you should check the Gmail documentation to see if it has some limitation on message size, or total number of messages sent. Looks like you're pumping too much data on the socket.