0
private void button1_Click(object sender, EventArgs e)
{
    SendMaxInvoice();
    try
    {
        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
        mail.From = new MailAddress("fromexample@gmail.com");
        mail.To.Add("toexample@gmail.com");
        mail.Subject = "Test Mail - 1";
        mail.Body = "mail with attachment";

        System.Net.Mail.Attachment attachment;
        attachment = new System.Net.Mail.Attachment(@"C:\Users\User\Desktop\dee.txt");
        mail.Attachments.Add(attachment);

        SmtpServer.Port = 587;
        SmtpServer.Credentials = new System.Net.NetworkCredential("fromexample@gmail.com", "*******");
        SmtpServer.EnableSsl = true;

        SmtpServer.Send(mail);
        MessageBox.Show("mail Send");
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
}
Blue
  • 22,608
  • 7
  • 62
  • 92
Deepak
  • 1
  • Welcome to SO! Currently your question is lacking lots of information, like what your exact problem is. Please take your time for the [Tour](http://stackoverflow.com/tour), or at least take a look at [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) and also at [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and update your question accordingly. – bassfader Sep 22 '16 at 13:46
  • You may want to remove the email addresses from your code sample to stop them being found by address harvesters and used for spamming you. – Daz Sep 22 '16 at 13:48
  • A very quick search reveals the same question (answered) here: http://stackoverflow.com/questions/10698779/the-smtp-server-requires-a-secure-connection-or-the-client-was-not-authenticated?rq=1 – Daz Sep 22 '16 at 13:49

0 Answers0