发送电子邮件当我运行这段代码,我得到一个错误:无法获得C#来从Hotmail
System.Net.Mail.SmtpException:发送邮件失败。 ---> System.Net.WebException:无法连接到远程服务器 ---> System.Net.Sockets.SocketException:连接尝试失败,因为连接方在 时间段后没有正确响应,或建立的连接失败,因为连接主机 未能响应65.55.163.152:587
代码:
static void Main(string[] args)
{
string smtpAddress = "smtp.live.com";
int portNumber = 587;
bool enableSSL = true;
string emailFrom = "[email protected]";
string password = "xxxxxxxxxxx";
string emailTo = "[email protected]";
string subject = "Daily Email Check";
string body = "Email reached business exchange server from an external hotmail email account";
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFrom);
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = false;
try
{
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
{
smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);
}
}
catch (Exception e)
{
Console.WriteLine("Error\n\n {0}", e);
Console.ReadKey();
}
}
}
你确定你和smtp.live.com之间没有防火墙吗? – BugFinder