Marvin kakuru

Marvin kakuru

  • 1.4k
  • 359
  • 160.8k

email sending failure

Feb 22 2021 7:58 AM


hello forum. am having trouble sending emails from my windows which has been sending emails successfully till mid feb when i started failing to send emails. am getting an error "SmtpException was unhandled"
below is the code i have been using.

 private void SendEmail()
        {
            label10.Text = "100";
            label11.Text = "80";
            ProgressBar();

            string smtAddress = "smtp.mail.yahoo.com";
            int portNumber = 587;

            bool enableSSL = true;
      
            DateTime dat = DateTime.Parse(label55.Text.ToString());

            string emailFrom = label42.Text;
            string password = label54.Text;
            string emailTo = label44.Text;
            string subject = dat.ToString("dd/MM/yyyy") + " - " + label47.Text + " - " + label46.Text;
            string body = label45.Text;


            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(emailFrom);
                mail.To.Add(emailTo);
                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = true;

                //Attachments
                //mail.Attachments.Add(new Attachment("C:\\Import of Used clothing & stationary research.pdf"));

                SmtpClient smtp = new SmtpClient(smtAddress, portNumber);
                {
                    smtp.Credentials = new NetworkCredential(emailFrom, password);
                    smtp.EnableSsl = enableSSL;
                    
                    smtp.Send(mail);

                }

            }

        }

Answers (5)