error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required?
below my code
private void button1_Click(object sender, EventArgs e)
{
try
{
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.Port = 587;
client.EnableSsl = true;
client.Timeout = 100000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(
MailMessage msg = new MailMessage();
msg.To.Add(textBox1.Text);
msg.Subject = textBox2.Text;
msg.Body = textBox4.Text;
Attachment data = new Attachment(textBox3.Text);
msg.Attachments.Add(data);
client.Send(msg);
MessageBox.Show("Successfully Sent Message.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
textBox3.Text = dlg.FileName.ToString();
}
}