邮件发送无法连接到服务器,发送邮件失败,无法连接到远程服务器

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;

}

Solutions1

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!