2

I have been working on a project that involves sending emails, I finally got it to work but after a few days of not using my system, I tried running the code again and I was getting the "unable to connect to the remote server" error.

Please can anyone just check out the code for me, I've been on it now for more than a week.

    try
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress("***@gmail.com");
            mail.To.Add("******@gmail.com");
            mail.Subject = "Test";
            mail.Body = ("the mdfjvnloifvhsuifv");

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

            SmtpServer.Send(mail);
            Label1.Text = "MAIL SENT!!!";

        }
        catch (Exception ex)
        {
            Label1.Text = ex.ToString();
            //throw;
        }
bufh
  • 3,153
  • 31
  • 36
Rotimi Odu
  • 21
  • 1
  • 2

1 Answers1

1

This might have to do with the antivirus settings. And a strange behaviour is that, the problem does not show up when we are debugging using visual studio!