We help IT Professionals succeed at work.
Get Started

Sending emails from a web form

Last Modified: 2015-02-27

I am trying to make my asp.net web form send an email from @gmail.com to @gmail.com email address. Using code provided below. Obviously, "username@gmail.com" is replaced with the email address that sends an email and etc.

   Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New  _
        Net.NetworkCredential("username@gmail.com", "password")
            SmtpServer.Port = 587
            SmtpServer.Host = "smtp.gmail.com"
            mail = New MailMessage()
            mail.From = New MailAddress("yourusername@gmail.com")
            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

Open in new window

When the button is pressed, I receive the error message:

How can I fix it? Thanks!
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE