简体   繁体   中英

SMTPException : Unable to read data from the transport connection: net_io_connectionclosed

I know that this question looks like duplicate of dozens other questions while its not.

When ever i try to send an email on my local machine through my web application an SMTPException is thrown and the exceptions is :

//on this line : SmtpServer.Send(mail);
Unable to read data from the transport connection: net_io_connectionclosed.

While the code on production is working perfectly, the same code, the same connections, the same credentials, i'm using IP instead of alias, i tried to turn off the firewall on my local machine, and nothing helped me to fix this issue.

While on my local machine is used to work previously, can anyone give just a hint what could be the problem that raising this issue?

If you are on a residential internet connection, quite often your ISP will block outgoing email sends by blocking all outbound connections to port 25. This is quite common here in the US. Try connecting to a local email server over TCP/IP, or to one on your own internal network.

This thread contains some.

For instance: it looks like assigning a static IP might solve the problem.

What this error means is that System.net.mail was unable to find the smtp server.

The answer will vary depending on whether you have a fixed IP or a dynamic IP but, basically, you need to assign a valid IP to your smtp server.

With fixed IP's this is relatively straightforward. With dynamic IP's it takes a bit of tweaking.

Open the IIS Manager and check the properties for the smtp server.

In the Default SMTP Virtual Server's properties, in the "Access" tab, in the Connection Control and Relay dialogs, make sure that your local IP is assigned. ( In my case, it's 10.0.0.2... )

You may also need to modify your hosts file, to point 127.0.0.1 to your machine name. ( \\WINDOWS\\system32\\drivers\\etc\\hosts )

Then, in your code, assign your machine name to the smtp client :

 Dim client As New SmtpClient("yourmachinename") client.Send(mail)

Alternatively another guy in the same thread seems to have found a workaround for the SMTP connection not being correctly closed.

Set SmtpClient.ServicePoint.MaxIdleTime = 1 according to a supported work-around: http://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?FeedbackID=146711 which makes all smtp work properly.

Here's a complete sample:

 MailMessage msgMail = new MailMessage(); msgMail.To.Add(new MailAddress("info@somedomain.se")); msgMail.Subject = "Message from web"; msgMail.IsBodyHtml = true; msgMail.Body = "Test message"; SmtpClient Client = new SmtpClient(); /* uses settings form web.config */ Client.ServicePoint.MaxIdleTime = 1; /* without this the connection is idle too long and not terminated, times out at the server and gives sequencing errors */ Client.Send(msgMail); msgMail.Dispose();

System.Net.NetworkCredential(user, password); ///Wrong
System.Net.NetworkCredential(email, password); ///right

because some email server is shability

就我而言,在设置用户名和密码时,我不得不从Network Credentials删除Domain属性

您使用的 Gmail 帐户对每天/每月发送的电子邮件数量有限制,如果您超过该限制,它将拒绝任何进一步的外发电子邮件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM