Member Avatar for SeniorAlexandro

So I'm making a Program to Start/Restart/Stop and running commands from the Console for my Server.
Now when someone uses the console, I want to be alerted of it on my Mail.
I am using Visual Studio 2010.
This is my Code:

        Dim mail As New MailMessage
        Dim smtp As New SmtpClient
        Try
            mail.From = New MailAddress("mailwheretobealerted@testmail.com")

            mail.To.Add("mailwheretobealerted@testmail.com")

            mail.Subject = ("Text")


            mail.Body = ("Some other Text")

            Dim s As New SmtpClient("smtp.gmail.com")

            s.Port = 587

            s.EnableSsl = True

            s.Credentials = New Net.NetworkCredential("Mailthatalerts@testmail.com", "password")

            s.Send(mail)

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

Of course I hidden some of my personal informations but this is it, when I'm clicking on the button, I get THIS error:

The SMTP Server requires a secure connection or the client was not authenticated.
The server response was: 5.5.1 Authentification required. Learn more at

I have another Program that does the same on VB 2008, and it works fine.
Any help would be very appreciated.
Thank you in advance!

    Dim SmtpServer As New SmtpClient()
    Dim mail As New MailMessage()
    SmtpServer.Credentials = New Net.NetworkCredential("abc.def@gmail.com", "abc123def")
    SmtpServer.Port = 25
    SmtpServer.Host = "mail.google.com"
    mail = New MailMessage()
    mail.From = New MailAddress("abc.def@gmail.com")
    mail.To.Add("abc.ljk@gmail.com")
    mail.Subject = "Testing"
    mail.Body = subject
    SmtpServer.Send(mail)
    MsgBox("mail sent sucessfully")

Ur connections are correct...try putting ur credentials at first...the above code works for me.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.