Click here to Skip to main content
15,916,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 13-Sep-17 2:18am
Comments
Graeme_Grant 13-Sep-17 7:21am    
"the smtp server requires a secure connection or the client was not authenticated 5.7 57"

The answer is, you can't.
F-ES Sitecore 13-Sep-17 9:03am    
The network credentials are for the smtp server you are sending through, they're unrelated to the email account you are sending "from". If the client has a password attached to their accounts or not is irrelevant, you need to supply the correct credentials to your smtp server that allows you to send emails.

1 solution

Ummm... What part of this message do you not understand?

Quote:
the smtp server requires a secure connection or the client was not authenticated

The server being used REQUIRES a username and password or otherwise authenticated/secured connection to send an email.

Sending an email on whatever server they're using without a password is not an option.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900