Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have mail sending code which works fine till yesterday but now im facing a error Failure sending mail. i have checked for user name and password its correct the port is correct but still im getting this error please suggest solution here is my code

What I have tried:

<pre> Try

            Dim sb As New StringBuilder()

            Dim message As MailMessage = New System.Net.Mail.MailMessage("mailid@gmail.com", txtEmail.Text.Trim(), txtSubject.Text, txtMessage.Text)

            Dim smtp As New SmtpClient()

            smtp.Host = "smtp.gmail.com"

            smtp.Port = 587

            smtp.Credentials = New System.Net.NetworkCredential("mailid@gmail.com", "Password")

            smtp.EnableSsl = True

            message.IsBodyHtml = True


            smtp.Send(message)

            Response.Write("<script>alert ('Thanks for Contact us')</script>")
            ' Clear the textbox valuess
            txtName.Text = ""
            txtSubject.Text = ""
            txtMessage.Text = ""
            txtEmail.Text = ""
        Catch ex As Exception
        End Try
Posted
Updated 5-Feb-17 17:40pm
Comments
Ashwin. Shetty 5-Feb-17 23:39pm    
Please do share your error message
Dave Kreskowiak 6-Feb-17 0:26am    
Without knowing what the error message says you, and us, are just guessing at what the problem is.

1 solution

Quote:
Change your settings to allow less secure apps to access your account. If you want to allow access anyway, follow these steps:
Go to the "Less secure apps" section in My Account.
Next to "Access for less secure apps," select Turn on.
If you still can't sign in to your account, the "password incorrect" error might be caused by a different reason.
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 7-Feb-17 5:58am    
5
[no name] 20-Feb-17 5:52am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900