Click here to Skip to main content
15,895,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have developed the code for sending an email for contact us page.

i have got the following error,
Error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

Can anyone help me to solve this..whats wrong in my code?

Here is my code..

C#
        MailMessage msg = new MailMessage();
        msg.SubjectEncoding = System.Text.Encoding.UTF8;
        msg.IsBodyHtml = true;
        msg.BodyEncoding = System.Text.Encoding.UTF8;
        msg.Priority = MailPriority.High;
        string fromaddrs = @"domain mail id";
        string toaddrs = @"thendral.marlen@gmail.com";
        msg.From = new MailAddress(fromaddrs);
        msg.To.Add(toaddrs);
        msg.Subject = "VelFlora_Feedback";
        string body = "<table width="527" border="0" cellspacing="1" cellpadding="1">" +
                        "<tr>" +
                            "<td width="20%" height="20"><b>FirstName:</b> </td>" +
                            "<td width="80%">" + fname + "</td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td width="20%" height="20"><b>LastName:</b> </td>" +
                            "<td width="80%">" + lname + "</td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td height="20"><b>ContactNo:</b></td>" +
                            "<td>" + phone + "</td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td height="20"><b>EmailID:</b></td>" +
                            "<td>" + email + "</td>" +
                        "</tr>" +
                        "<tr>" +
                            "<td width="20%" height="20"><b>CompanyName:</b> </td>" +
                            "<td width="80%">" + com_name + "</td>" +
                        "</tr>" +
                         "<tr>" +
                            "<td width="20%" height="20"><b>CompanyWebsite:</b> </td>" +
                            "<td width="80%">" + com_site + "</td>" +
                        "</tr>" +
                         "<tr>" +
                            "<td width="20%" height="20"><b>Country:</b> </td>" +
                            "<td width="80%">" + country + "</td>" +
                    "</tr>" +
                          "<tr>" +
                            "<td height="20"><b>ContactAddress:</b></td>" +
                            "<td>" + address + "</td>" +
                        "</tr>" +
"<tr>" +
                            "<td height="20"><b>Queries:</b></td>" +
                            "<td>" + query + "</td>" +
                        "</tr>" +
                        "</table>";

        msg.Body = body.ToString();
        SmtpClient client = new SmtpClient();
        client.Credentials = new System.Net.NetworkCredential(fromaddrs, "password");
        client.Port = 587;
        client.Host = "smtp.gmail.com";
        client.EnableSsl = true;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        try
        {
            client.Send(msg);
            return 1;

        }
        catch (Exception ex1)
        {
            return -1;
        }



[edit]Code block added, HTML characters encoded - OriginalGriff[/edit]
Posted
Updated 22-Dec-11 19:22pm
v3

1 solution

Check that your fromaddrs and the password "strike123" match, and are valid for sending emails (do it manually if you need to, send an email by hand using those credentials).
If they aren't, you will get than message.
 
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