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.