Hi,
I have a problem with sending email in vb.net.
When I want to send an email this error will be shows to me:
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 at
at 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 Mil_Maker.Form9.sendEmail() in F:\USB\My Apps\Auto Letter Creater\V2.3\making letter automaticly\making letter automaticly\Form9.vb:line 22
Or:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
And this is my code:
Sub sendEmail()
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New Net.NetworkCredential(Trim(TextBox1.Text), Trim(TextBox2.Text))
SmtpServer.Port = "587"
If ComboBox2.Text.Contains("gmail") Then
SmtpServer.EnableSsl = True
Else
SmtpServer.EnableSsl = False
End If
SmtpServer.Host = ComboBox2.Text
mail.From = New MailAddress(Trim(TextBox1.Text))
mail.To.Add(Trim(TextBox3.Text))
mail.Subject = Trim(TextBox5.Text)
mail.Body = Trim(Form1.RichTextBox1.Text)
SmtpServer.Send(mail)
MsgBox("Mail Sent", MsgBoxStyle.Information, "Mail Sent")
Me.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
I want to send email from gmail but this code just work for yahoo mails.
How I can solve this problem???
Please help me.
Thank You.