Click here to Skip to main content
15,942,710 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
I need your help.

Can you suggest me which code is wrong.

When i submit some details on contact form then i received a error MSG -

"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"

can you help me... urgent basic ..

below mentioned code -

VB
protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        if (Validation())
        {
            try
            {
                SqlCommand cmd = new SqlCommand("Insert into Enquiry values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + DropDownList1 .SelectedValue + "','" + TextBox5.Text + "','"+TextBox6.Text +"','"+TxtDegree .Text +"')", con);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                


SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Host = "smtp.gmail.com";          

client.Port = 587;
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential("xyz@gmail.com",
"*******");
client.UseDefaultCredentials = false;
client.Credentials = credentials;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("xyz@gmail.com");
msg.To.Add(new MailAddress("xyz@gmail.com"));
msg.Subject = "Enquiry";
msg.IsBodyHtml = true;
msg.Body = string.Format("<html><head></head><body>ENQUIRY<BR><hr><br> Name : "+TextBox1 .Text +"<br> Email : "+TextBox2 .Text +"<br> Phone : "+TextBox3 .Text +"<br>Course : "+DropDownList1 .SelectedValue+"<br> Degree :"+TxtDegree .Text +"<br> Message : "+TextBox5 .Text +"</body>");
//msg.Body = string.Format("<html><head></head><body>"+TextBox1 .Text +"</body></html>");
//try
//{
client.Send(msg);
//lblMsg.Text = "Your message has been successfully sent.";
//}
//catch (Exception ex)
//{
//// lblMsg.ForeColor = Color.Red;
//lblMsg.Text = "Error occured while sending your message." +
//ex.Message;

//}
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox6.Text = "";
DropDownList1.SelectedValue = "0";
TextBox5.Text = "";
TxtDegree.Text = "";

Label1.Text = "Enquiry submitted!";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
    }
    protected bool Validation()
    {
        if (TextBox1.Text.Trim() == "")
        {
            Label1.Text = "Enter name!";
            TextBox1.Focus();
            return false;
        }
        if (TextBox2.Text.Trim() == "")
        {
            Label1.Text = "Enter email id!";
            TextBox2.Focus();
            return false;
        }
        if (TextBox3.Text.Trim() == "")
        {
            Label1.Text = "Enter phone no!";
            TextBox3.Focus();
            return false;
        }
        //if (TextBox4.Text.Trim() == "")
        //{
        //    Label1.Text = "Enter course!";
        //    TextBox4.Focus();
        //    return false;
        //}
        if (TextBox5.Text.Trim() == "")
        {
            Label1.Text = "Enter message!";
            TextBox5.Focus();
            return false;
        }
        return true;
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("Default.aspx");
    }
}
Posted
Updated 29-May-14 7:39am
v3

Hello Priyanka,

There are many causes for this to occur,with your code iam unable to identify the issue

You can refer these quickly to try and solve yourself

http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail[^]

http://stackoverflow.com/questions/18503333/the-smtp-server-requires-a-secure-connection-or-the-client-was-not-authenticated[^]

All the Best:)
 
Share this answer
 
Comments
Priyanka Ksyap 30-May-14 12:30pm    
Thanks, It's solve
karthik Udhayakumar 31-May-14 8:37am    
Welcome:)
Hello ,
This problem occurs may be for weak password .
Refer link : 5.5.1 Authentication Required with smtp.gmail.com
also check : This

thanks
 
Share this answer
 
the problem is small password.You have to use a Strong PAssword.
 
Share this answer
 

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