Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Here is the code for my contact page, as i'm running with my local machine when i click submit i'm getting the error as "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."

please help where am i missing.
C#
protected void Btnsubmit_Click(object sender, EventArgs e)
{

    MailMessage mm = new MailMessage("sender@gmail.com", "reciver@gmail.com");
    mm.Subject = txtSubject.Text;
    mm.Body = "Name: " + txtName.Text + "<br /><br />Email: " + txtEmail.Text + "<br />" + txtMessage.Text;            
    mm.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.EnableSsl = true;
    System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
    NetworkCred.UserName = "sender@gmail.com";
    NetworkCred.Password = "password";
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = NetworkCred;
    smtp.Port = 587;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.Send(mm);
    lblResult.Text = "Email Sent SucessFully.";
}

and i have used the below code in my web.config
XML
<system.net>
<mailSettings>
<smtp  from="sender@gmail.com">
<network host="smtp.gmail.com" port="587" enableSsl ="true" userName="sender@gmail.com" password="password">
</smtp>
</mailSettings>
</system.net>


please help...
Posted
Updated 9-Jul-14 1:48am
v2
Comments
jo.him1988 9-Jul-14 8:05am    
your code is right make sure about your password or once again log on to your gmail account

1 solution

your code looks all right to me, sometimes this may due to weak password.
check This answer[^]
 
Share this answer
 
Comments
ammu189 10-Jul-14 1:02am    
hi Damith thank you so much for your reply.. changing password worked out..:)
DamithSL 10-Jul-14 1:30am    
you are welcome!

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