requires starttls

how to I fix I get an error that it requires a starttls
Imports System.Net.Mail
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New Net.NetworkCredential("", "password")
            SmtpServer.Port = 587
            SmtpServer.Host = ""
            mail = New MailMessage()
            mail.From = New MailAddress("", "my name")
            mail.Subject = "Test Mail"
            mail.Body = "This Is for testing SMTP mail from GMAIL"
            MsgBox("mail send")
        Catch ex As Exception
        End Try
    End Sub
End Class
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael FowlerSolutions ConsultantCommented:
try setting enableSSL to true

SmtpServer.EnableSsl = true;

Open in new window
HalCHubAuthor Commented:
nope here is a different version

    Private Sub test(Optional ByVal smtp As String = "")
        Dim toAdd As String = ""
        Dim fromAdd As String = ""
        Dim pass As String = "pswd"
        Dim client As SmtpClient = New SmtpClient(smtp)
        Dim mail As New MailMessage
        mail.From = New MailAddress(fromAdd)
        mail.Subject = "Test Zip File"
        mail.Body = "This Is just a test"
        client.Port = 465 '465 587  25
        client.Credentials = New System.Net.NetworkCredential(fromAdd, pass)
        client.EnableSsl = True
        '   client.Timeout = Int32.MaxValue

        Catch ex As SmtpException
        End Try
    End Sub

port 465 times out
port 25 gives a starttls error
port 587 give required secure connection
Michael FowlerSolutions ConsultantCommented:
Your code looks fine, assuming you are using a valid email/user/pass in your actual code.

This google support article has more ideas for testing

The first is to confirm that you can log into the account you are using manually and so validate your credentials

Another good test is telnet to confirm that a connection can be made from your machine
eg telnet 587
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Rafiq J.Net DeveloperCommented:
<network host="" enableSsl="true" ... />
Rafiq J.Net DeveloperCommented:
Rafiq J.Net DeveloperCommented:
try this logic

 string fromaddr = "";
        string toaddr = TextBox1.Text;//TO ADDRESS HERE
        string password = "YOUR PASSWROD";

        MailMessage msg = new MailMessage();
        msg.Subject = "Username &password";
        msg.From = new MailAddress(fromaddr);
        msg.Body = "Message BODY";
        msg.To.Add(new MailAddress(TextBox1.Text));
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "";
        smtp.Port = 587;
        smtp.UseDefaultCredentials = false;
        smtp.EnableSsl = true;
        NetworkCredential nc = new NetworkCredential(fromaddr,password);
        smtp.Credentials = nc;

Like me if it's helps

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.