使用System.Net.Mail和outlook.com发送电子邮件

时间:2015-04-11 16:28:47

标签: c# email outlook

代码:

MailMessage mail = new MailMessage("name@hotmail.com", "name@hotmail.com");
            SmtpClient client = new SmtpClient();
            client.Port = 587;
            client.Host = "smtp-mail.outlook.com";
            client.EnableSsl = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential("name@hotmail.com", "password");

            mail.Subject = "this is a test email.";
            mail.Body = "this is my test email body";
            client.Send(mail);
  

错误消息:异常:发送消息失败。的InnerException:   无法连接到远程服务器。连接尝试失败   因为关联方在一段时间后没有正确回应   时间或建立的连接失败,因为连接的主机有   未能回应65.55.176.126:587

我可以使用浏览器登录帐户。我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

切换到smtp.gmail.com,它有效。我将让微软在未来解决这个问题!