Click here to Skip to main content
15,940,246 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to send email using gmail, below is my code

SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("", "From Me");
MailAddress toAddress = new MailAddress("", "To You");
message.From = fromAddress;
message.Subject = "Testing!";
message.Body = "This is the body of a sample message";
smtpClient.Host = "";
smtpClient.Credentials = new System.Net.NetworkCredential("username", "password");

smtpClient.EnableSsl = true;

smtpClient.Port = 587;

I am getting this error "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."
Password and username is all correct, i tried lot of things but not working :(

Plz anyone help me

Updated 17-Mar-11 19:40pm

Hope this[^] might help you.
Share this answer

You did not specified Smtpclient name in your SmtpClient() object.
Just add this line above the declaration of new SmtpClient(); object.

String server= "";

and pass the string parameter to smtpclient object like this :
SmtpClient smtpClient = new SmtpClient(server);

instead of "SmtpClient smtpClient = new SmtpClient();"

this will work.. :)
Share this answer
ProgrammerAt 18-Mar-11 2:11am    
Hi Kapil,
your code worked :) thanks a lot.

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