1
using(SmtpClient client = new SmtpClient("smtp.gmail.com", 587)) 
{
    // Configure the client
    client.EnableSsl = true;
    client.UseDefaultCredentials = false;
    client.Credentials = new NetworkCredential(textBox1.Text, textBox3.Text);

    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    MailMessage message = new MailMessage(
    textBox1.Text, // From field
    textBox2.Text, // Recipient field
    textBox4.Text, // Subject of the email message
    richTextBox1.Text // Email message body
    );

    client.Send(message);

    MessageBox.Show("Email has been sent.");
}

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

I have been getting this error with gmail but am able to use other SMTP Servers to send mails. The credentials are correct.

Robert
  • 5,278
  • 43
  • 65
  • 115
sooraj
  • 11
  • 1
  • 1
  • 2

3 Answers3

5

Looks like there is a security issue with Gmail account.

I have also faced that same issue and then found solution from this post.

The post mentioned that you need to change the Account Permission setting with "Access of Less secure App" Enabled.

In fact you will get notification when you logged in to your gmail account.

Jenish Rabadiya
  • 6,708
  • 6
  • 33
  • 62
Jinesh Jain
  • 1,232
  • 9
  • 23
  • I have the same problem, but your solution doesn't resolve my problem.. When i send mail, the service is not aviable, sorry for my bad english – Nopesound Feb 12 '16 at 06:41
3
    message.To.Add(new MailAddress("abc@abc.com));  // replace with valid value 
        message.From = new MailAddress("abc@abc.com", "Contact Form");
        message.Subject = Subject;
        message.Body = string.Format(NewBody);
        message.IsBodyHtml = true;
        using (var smtp = new SmtpClient())
        {
            var credential = new NetworkCredential
            {
                UserName = "abc@gmail.com",  // replace with valid value
                Password = "qwerty123456"  // replace with valid value
            };
            smtp.Credentials = credential;
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.Send(message);
        }

Just This is working code for me you can use it,Only Problem with this code is sometime mails are coming in spam Folder.

Neeraj Mehta
  • 1,675
  • 2
  • 22
  • 45
  • It would help to specify what "valid value" means; what password is used in NetworkCredential.Password; is it the Google password or the email account password? – Sam Hobbs Feb 16 '17 at 18:01
0

You need to enable two step authentication for you Gmail account and get application password. Then use that password instead of regular one.