Durga Velusamy

Durga Velusamy

  • NA
  • 318
  • 115.2k

how to send mail from win form

Nov 21 2015 7:20 AM
 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(
"[email protected]", "durga12345678");
MailMessage msg = new MailMessage();
msg.To.Add(textBox1.Text);
msg.From = new MailAddress("[email protected]");
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();
}
}

Answers (5)