How to fix error while sending email from windows from?

SIC Team 5 Reputation points
2025-01-23T10:36:57.5933333+00:00

System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.

at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)

at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)

at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)

at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)

at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)

at System.Net.Mail.SmtpClient.GetConnection()

at System.Net.Mail.SmtpClient.Send(MailMessage message)

--- End of inner exception stack trace ---

at System.Net.Mail.SmtpClient.Send(MailMessage message)

Community Center Not monitored
{count} votes

1 answer

Sort by: Most helpful
  1. ザイ 文杰 0 Reputation points
    2025-02-13T02:36:52.7366667+00:00

    Hi , I have a same problem.

    Here is my code with asp.net interface & vb.net behind.


            Dim mailer As New System.Net.Mail.SmtpClient()
    
            Dim mailMsg As New System.Net.Mail.MailMessage()
    
            With mailMsg
    
                .From = New System.Net.Mail.MailAddress(<my maildress>)
    
                .Subject = "Test"
    
                .Body = "Test"
    
            End With
    
            With mailer
    
                .Host = "smtp-mail.outlook.com"
    
                .EnableSsl = True
    
                .Port = 587
    
                .Credentials = New System.Net.NetworkCredential(<my maildress>, <my password>)
    
            End With
    
            Try
    
                mailMsg.To.Add(New System.Net.Mail.MailAddress(<my mailadress>))
    
                mailer.Send(mailMsg)
    
            Catch ex As Exception
    
                Throw ex
    
            End Try
    

    Thank you!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.