Click here to Skip to main content
15,891,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
While sending mail I have got this error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

In my domain also it will not accept and the mail was not send.

Can anyone help me to solve this. Whats the problem in my code?

Here is my code,
C#
string admin_mail = "karthikeyan.marlen@gmail.com";
            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("karthikeyan.marlen@gmail.com");
                message.To.Add(lmail + "," + admin_mail);
                message.CC.Add("thendral.marlen@gmail.com");
                message.Subject = "UserName_and_Pwd";
                message.SubjectEncoding = System.Text.Encoding.UTF8;
                message.Subject = "Strikeaprice-Registration";
                message.IsBodyHtml = true;

                message.Body = "UserName ='" + un + "' and Pwd='" + pd + "'";
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.Priority = MailPriority.High;


                SmtpClient mailClient = new SmtpClient();
                mailClient.Credentials = new System.Net.NetworkCredential("username", "password");
                mailClient.UseDefaultCredentials = true;
                mailClient.Port = 587; // Gmail works on this port
                mailClient.Host = "smtp.gmail.com";
                mailClient.EnableSsl = true; //Gmail works on Server Secured Layer 

                try
                {
                    mailClient.Send(message);
                    message.Dispose();
                    return 1;
                }
                catch (Exception s)
                {
                    throw (s);
                }
            }
            catch (Exception e)
            {
                throw (e);
            }
Posted
Updated 20-Dec-11 23:48pm
v3

1 solution

 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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