我一直在从事一个涉及发送电子邮件的项目,我终于让它工作了,但几天没有使用我的系统后,我尝试再次运行代码,但收到“无法连接到远程服务器”的消息错误。
请任何人帮我查看一下代码,我已经使用它一个多星期了。
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;
}
这可能与防病毒设置有关。 奇怪的是,当我们使用 Visual Studio 进行调试时,问题并没有出现!