Hello
I'm trying to send emails using smtp and getting an error
This is my code :
Imports System.Net.Mail
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SendEmail()
End Sub
Public Sub SendEmail()
Dim client As New SmtpClient()
Dim sendTo As New MailAddress("shtrees@gmail.com")
Dim from As MailAddress = New MailAddress("shtrees@gmail.com")
Dim message As New MailMessage(from, sendTo)
message.IsBodyHtml = True
message.Subject = "HI"
message.Body = "Got it!!"
' Use the same account in app.config to authenticate.
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("shtrees@gmail.com", "THEPASSWORD")
client.Host = "smtp.gmail.com"
client.UseDefaultCredentials = False
client.Credentials = basicAuthenticationInfo
client.EnableSsl = True
Try
client.Send(message)
MsgBox("SUCCESS")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
This is the error i am having :
---------------------------
SMTPSendmail
---------------------------
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more atat System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)
at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)
at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at SMTPSendmail.Form1.SendEmail() in C:\Users\A1A4A\Desktop\Projects\Visual Basic 08\SMTPSendmail\SMTPSendmail\Form1.vb:line 23
---------------------------
OK
---------------------------
I tried changing the "To" to a hotmail account but still having the exact same error
I am 100% sure of my email and password. ( shtrees@gmail.com )
As i am sure that i can send emails to myself ( To and From are the same )
I am using Visual basic 2008
Please help me finding the problem
Thanks