Question Need help with email code

fantity

Active member
Joined
Mar 10, 2012
Messages
27
Programming Experience
Beginner
I am making a very simple SMTP emailer. This is the code:
VB.NET:
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 AnEmailMessage As New MailMessage
        AnEmailMessage.From = New MailAddress("xxx@gmail.com")
        AnEmailMessage.Subject = (TextBox1.Text)
        AnEmailMessage.Body = (MaskedTextBox1.Text)
        AnEmailMessage.Priority = MailPriority.High
        Dim SimpleSMTP As New SmtpClient("smtp.gmail.com")
        SimpleSMTP.Port = 587
        SimpleSMTP.EnableSsl = True
        SimpleSMTP.Credentials = New System.Net.NetworkCredential(xxx@gmail.com", "xxx")
        SimpleSMTP.Send(AnEmailMessage)
        MsgBox("The message was sent.", MsgBoxStyle.OkOnly, "Message Sent !")


    End Sub
End Class

This is the error I get when I press send:
Capture.PNG
 
You haven't specified a recipient, the receiver that you want to send the email to.
 
You haven't specified a recipient, the receiver that you want to send the email to.

Ok I added a recipient but when I click send now I get this:

VB.NET:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
 
The code works fine for me for Gmail. I guess check your Gmail credentials.
 
Back
Top