SMTP Email Error: Unable to connect to the remote server

Last Reply one month ago By dharmendr

Posted one month 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

 

You are viewing reply posted by: dharmendr one month ago.
Posted one month 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