Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
here is my code:
C#
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    message.To.Add("test@gmail.com");
                    message.Subject = "Nici un Clinet valabil pentru reparare";
                    message.From = new System.Net.Mail.MailAddress("test@gmail.com");
                    message.Body = "Nu mai sunt clienti la care mecanicii sa lucreze";
                    string sendEmailsFrom = "test@gmail.com";
                    string sendEmailsFromPassword = "my_invisible_password";
                    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
                    smtp.EnableSsl = true;
                    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    smtp.Credentials = new NetworkCredential(sendEmailsFrom, sendEmailsFromPassword);
                    smtp.Timeout = 20000;
                    smtp.Send(message);


And my error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

What is the problem? i can't see it and can't find a solution on google.

Thanks,
Sas Gabriel

What I have tried:

email
Posted
Updated 2-Mar-17 19:56pm
v2
Comments
Richard Deeming 19-Dec-16 12:50pm    
I see you've edited your question to remove your email address. However, it's still visible in the revision history. You'll need to contact the site administrators to get that removed.

You need to set
C#
UseDefaultCredentials = false;
first and after that set the credentials you want to use

C#
Credentials = new NetworkCredential("gabitza.sas@gmail.com", "my_invisible_password");


Also make sure you can login from with your username and password from the mail.google.com page.

Good luck,
OI
 
Share this answer
 
Comments
Gabriel Sas 12-Nov-12 17:04pm    
also the password wasn't the good one, thanks
veera kishore 3-Oct-16 8:17am    
pls tell me i don't know how to add this credential

this is my code pls make sure tell me the solution.

if (ds.Tables[0].Rows.Count > 0)
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtEmail.Text);
// Recipient e-mail address.
Msg.To.Add(txtEmail.Text);
Msg.Subject = "Your Password Details";
Msg.Body = "Hi, Please check your Login DetailssYour uname: " + ds.Tables[0].Rows[0]["uname"] + "Your pass: " + ds.Tables[0].Rows[0]["pass"] + "";
Msg.IsBodyHtml = true;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("yourusername@gmail.com", "yourpassword");
Credentials = new NetworkCredential("yourusername@gmail.com", "yourpassword");
smtp.EnableSsl = true;
smtp.Send(Msg);
//Msg = null;
lbltxt.Text = "Your Password Details Sent to your mail";
veera kishore 3-Oct-16 8:18am    
i used this usedefaultcredential= false as you said..but i had error here.pls find solution
Also please be aware that google will block you from logging in when you do to much connection attempts.

I always use a local email server for development: http://www.hmailserver.com/[^]
It's free. You can simply configure it and run it on your computer, connecting to localhost:2525.
Please be sure to also turn down the ban-option ("auto-ban") of this one.
 
Share this answer
 
Goto Account of Gmail , then select Connected apps & sites Allow less secure apps: ON(if this is off you cannot send mails through apps,or your websites )
 
Share this answer
 
Comments
Graeme_Grant 3-Mar-17 2:05am    
Again, any reason why you are replying to a 5-year-old question?

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