SMTP Email Error: Unable to connect to the remote server

Last Reply 3 months ago By dharmendr

Posted 3 months ago

Getting error Unable to connect to the remote server while trying to send mail

Private Function SendEmail() As Boolean
    Dim mm As New MailMessage("test@gmail.com", "test1@gmail.com")
    mm.Subject = "Test"
    mm.Body = "test"
    mm.IsBodyHtml = True
    Dim smtp As New SmtpClient()
    smtp.Host = "smtp.gmail.com"
    smtp.Port = 25
    smtp.EnableSsl = False
    Dim NetworkCred As New NetworkCredential()
    NetworkCred.UserName = "test@gmail.com"
    NetworkCred.Password = "test"
    smtp.UseDefaultCredentials = True
    smtp.Credentials = NetworkCred
    Try
        smtp.Send(mm)
    Catch e As Exception
        Response.Write(e.Message)
    End Try
    Return True
End Function

 

Posted 3 months ago
rani says:
smtp.Port = 25
    smtp.EnableSsl = False

Your Firewall is blocking port 25.

Set the Port number to 587 or 465 and EnableSsl to True.

Private Function SendEmail() As Boolean
    Dim mm As New MailMessage("test@gmail.com", "test1@gmail.com")
    mm.Subject = "Test"
    mm.Body = "test"
    mm.IsBodyHtml = True
    Dim smtp As New SmtpClient()
    smtp.Host = "smtp.gmail.com"
    smtp.Port = 587
    smtp.EnableSsl = True
    Dim NetworkCred As New NetworkCredential()
    NetworkCred.UserName = "test@gmail.com"
    NetworkCred.Password = "test"
    smtp.UseDefaultCredentials = True
    smtp.Credentials = NetworkCred
    Try
        smtp.Send(mm)
    Catch e As Exception
        Response.Write(e.Message)
    End Try
    Return True
End Function