Sir,
I am using two accounts to send an email. Both of these accounts are creaton on GMAIL server. But when i am using first account, it would allows to send email successfully. But if i use second account it gives me below error.
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.
Why is it so?
I am using below .vb code
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Try
Dim x As String = ""
Dim mail1 As MailMessage = New MailMessage()
mail1.From = New MailAddress(tname.Text.Trim & "<hoteloceangrand@gmail.com>")
mail1.To.Add("hoteloceangrand@gmail.com")
mail1.Subject = "Hotel Ocean Grand :: Booking Request from (" & tname.Text.Trim & ")"
x = "<a href='http://hoteloceangrand.in' title='Hotel Ocean Grand'><img border='0' src='http://hoteloceangrand.in/images/logo.png' alt='Hotel Ocean Grand'/></a><br/><br/><br/>"
x += "<font size='2' color='#474747'>Full Name: </font><strong>" & tname.Text.Trim & "</strong><br/><br/>"
x += "<font size='2' color='#474747'>Email Address: </font><strong>" & temail.Text.Trim & "</strong><br/><br/>"
x += "<font size='2' color='#474747'>Contact No: </font><strong>" & contactno.Text.Trim & "</strong><br/><br/>"
x += "<font size='2' color='#474747'>Check In Date (mm/dd/yyyy): </font><strong>" & checkin.Text.Trim & "</strong><br/><br/>"
x += "<font size='2' color='#474747'>Check Out Date (mm/dd/yyyy): </font><strong>" & checkout.Text.Trim & "</strong><br/><br/>"
x += "<font size='2' color='#474747'>Message: </font><strong>" & Replace(message.Text.Trim, vbCrLf, "<br/>") & "</strong><br/><br/>"
mail1.IsBodyHtml = True
mail1.Body = x
Dim smtp As SmtpClient = New SmtpClient("smtp.gmail.com", 587)
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential("hoteloceangrand@gmail.com", "xxxxxx")
smtp.Send(mail1)
label1.Text = "Thanks for your interest! We will contact you soon..."
clearall()
Catch ex As Exception
label1.Text = ex.ToString
End Try
End Sub