Hi...
I have one vb.net console application which is running on many client sites for sending an email. All client provided email id, server name, port, and password.
but this client is saying that they don't have any password for emails. they are using their mail without a password.
I tried with a code from google to send email without a password, which is working with my companies mail id. but still, in client side it throwing an error.
the smtp server requires a secure connection or the client was not authenticated 5.7 57
What I have tried:
Try
ServicePointManager.ServerCertificateValidationCallback = _
New System.Net.Security.RemoteCertificateValidationCallback(AddressOf customCertValidation)
Dim Smtp_Server As New SmtpClient
Dim mailobj As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
If rbtnWithPass.Checked = True Then
Smtp_Server.Credentials = New Net.NetworkCredential(txtFrom.Text.Trim, txtPassword.Text.Trim)
mailobj.Subject = "Test mail with password"
Else
Smtp_Server.Credentials = System.Net.CredentialCache.DefaultCredentials
mailobj.Subject = "Test mail without password"
End If
Smtp_Server.Port = txtPort.Text.Trim
Smtp_Server.EnableSsl = False
If rbtnServer.Checked = True Then
Smtp_Server.Host = txtServerName.Text.Trim
Else
Smtp_Server.Host = txtServerIP.Text.Trim
End If
mailobj = New MailMessage()
mailobj.From = New MailAddress(txtFrom.Text.Trim)
Dim toArr As String()
toArr = txtTo.Text.Trim.Split(",")
For Each toStr As String In toArr
Dim val As String = toStr.Replace(vbLf, "")
mailobj.[To].Add(val)
Next
Dim ccArr As String()
ccArr = txtTo.Text.Trim.Split(",")
For Each ccStr As String In ccArr
Dim val As String = ccStr.Replace(vbLf, "")
mailobj.CC.Add(New Net.Mail.MailAddress(val))
Next
mailobj.Body = txtBody.Text.Trim + vbLf + vbLf
Smtp_Server.Send(mailobj)
MsgBox("Email send successfully. From:" & txtFrom.Text.Trim & " To: " & txtTo.Text.Trim & " Time : " & Now)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Private Function customCertValidation(ByVal sender As Object, _
ByVal cert As X509Certificate, _
ByVal chain As X509Chain, _
ByVal errors As Net.Security.SslPolicyErrors) As Boolean
Return True