Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using smtpclient to send a mail.Here is my code.
while sending it will show an error like
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

can any one tell what is the problem to sending mail?

public int sendmail(string name, string pwd,string email)
        int i = 0;
        MailMessage ms = new MailMessage();
        ms.From = new MailAddress(@"ValidEmailAddress");
        ms.Subject = "Username and Password";
        ms.SubjectEncoding = System.Text.Encoding.UTF8;
        ms.IsBodyHtml = true;
        ms.Body = "UserName='" + name + "' and Password='" + pwd + "'";
        ms.BodyEncoding = System.Text.Encoding.UTF8;
        ms.Priority = MailPriority.High;
        SmtpClient clt = new SmtpClient();
        clt.Credentials = new System.Net.NetworkCredential("ValidEmailAddress", "ValidPassword");
        clt.Port = 587;
        clt.Host = "ValidHost";
        clt.EnableSsl = true;

            i = 1;
        catch(Exception err) 
        return i;

[Edit] Reiss - removed user details [/Edit]
Updated 11-Oct-11 1:28am
André Kraak 11-Oct-11 7:28am    
I hope that is not your real password in the code, if so change your password for your Gmail account immediately.
Thendral.N 11-Oct-11 7:31am    
ya..i have changed..

thanks for your kind information

Share this answer
The SMTP server requires a secure connection or the client was not authenticated.

this line says that either your smtp server allows only secured connection

that means your server has some security and while sending mail you need to enable it

eg to enable ssl security


and since you have did it

check the credentials specified by you is right or wrong.
Share this answer
clt.UseDefaultCredentials = false;

and also check your cardentials are right.
Share this answer
Check your network credential i.e userid and password are correct or not

and add this line to ur code

Clt.UseDefaultCredentials = false;

refer this link[^]
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