1

I have a problem trying to make the user of my program send an Email to my Gmail account, this my Setup:

enter image description here

And this is my code:

Imports System.Net.Mail

Public Class Form1
Private Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtBody.TextChanged
    lblCharCount.Text = String.Format("Letter Count: {0}", txtBody.Text.Length)
End Sub

Private Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSend.Click
    If YourEmailTextBox.Text <> "" AndAlso txtBody.Text <> "" Then
        Dim message As New MailMessage
        Dim smtp As New SmtpClient
        message.To.Add(YourEmailTextBox.Text.Trim())
        message.From = New MailAddress(YourEmailTextBox.Text, "heading")
        message.Subject = txtSubject.Text
        message.Body = txtBody.Text
        smtp.Host = "smtp.gmail.com"
        smtp.Port = "587"
        smtp.EnableSsl = True
        smtp.Credentials = New Net.NetworkCredential("MyGmailAccount@gmail.com", "MyPassword")
        Try
            smtp.Send(message)
            MsgBox("your message has been sent")

        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
    Else
        MsgBox("Please enter a message into the body and the email address of the recipient", MsgBoxStyle.Information)
    End If
End Sub
End Class

And this is the problem :

enter image description here

Some help Please...

Mousa Alfhaily
  • 1,260
  • 3
  • 20
  • 38

1 Answers1

0

Can't see what's behind your error box, but you're probably not setting the smtp.Credentials correctly. Here's an example: http://www.codeproject.com/Articles/20546/How-to-Send-Mails-from-your-GMAIL-Account-through

Also see: Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

Community
  • 1
  • 1
EAnders
  • 112
  • 8
  • I tried them all.... nothing work. I believe that problem not in the code. Something goes wrong and i don't know what it could be.[EAnders](http://stackoverflow.com/users/5179009/eanders) – Mousa Alfhaily Aug 14 '15 at 16:57
  • Google send me a "Sign-in attempt prevented", i don't know what's happening – Mousa Alfhaily Aug 14 '15 at 17:01
  • 1
    Try this: http://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not – EAnders Aug 14 '15 at 17:04
  • Yes, it's work, thanks a lot[EAnders](http://stackoverflow.com/users/5179009/eanders) – Mousa Alfhaily Aug 14 '15 at 17:51