This is because you are using the wrong port number, google's gmail uses port 465, change the 587 and it should work (provided the username+password are correct).
SMTP Mail Error, Failure Sending Mail
-
29-06-2023 - |
Question
Im facing a problem when i want to sent email when to submit form. The problem is SMTP Mail error. when run it i get Message "Failure sending mail." and for the Innerexecption"Unable to connect to the remote server". below is my code:
< Protected Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Dim conn As New MySql.Data.MySqlClient.MySqlConnection
Dim strConnectionString As String = ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString
Try
conn.ConnectionString = strConnectionString
conn.ConnectionString = "server=localhost;user id=root;persistsecurityinfo=False;database=test;password=1234"
conn.Open()
Catch ex As MySql.Data.MySqlClient.MySqlException
MessageBox.Show(ex.Message)
End Try
Dim sqlConn As New MySqlConnection(strConnectionString)
sqlConn.Open()
Dim sqlComm As New MySqlCommand()
sqlComm.Connection = sqlConn
Dim msg As MailMessage
Dim email As String = String.Empty
Dim SmtpServer As New SmtpClient("smtp.gmail.com", 587)
msg = New MailMessage()
email = TextBox3.Text.Trim()
'sender email address
msg.From = New MailAddress("****s@gmail.com")
'Receiver email address
msg.[To].Add(email)
msg.Subject = "Change Request have Been Submitted By:"
msg.Body = "Hi " & TextBox1.Text.Trim() & "!" & vbLf & "Thanks for Submitted the Change Request Online " & vbLf & "Thanks!"
msg.IsBodyHtml = True
SmtpServer.Credentials = New NetworkCredential("****s@gmail.com", "******")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
SmtpServer.EnableSsl = True
SmtpServer.Send(msg)'THIS LINE IT SHOW THE ERROR'
' UserControl()
Try
ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "Message", "alert('Your Change Request have been submitted.');", True)
Catch ex As Exception
ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "Message", "alert('Error occured : " & ex.Message.ToString() & "');", True)
Return
Finally
email = String.Empty
sqlConn.Close()
sqlComm.Dispose()
End Try
Response.Redirect("Default.aspx")
End Sub>
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow