我正在尝试向自己的Hotmail发送电子邮件,但发生了此错误:
无法连接到远程服务器
遵循发送电子邮件的代码方法:
public void SendEmailToClient(string email, string subject, string content)
{
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential = new NetworkCredential("thiago.friedman@hotmail.com", "123");
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("thiago.friedman@hotmail.com");
smtpClient.Port = 25;
smtpClient.Host = "smtp.live.com";
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
message.From = fromAddress;
message.Subject = subject;
message.Body = content;
message.To.Add("thiago.friedman@hotmail.com");
try
{
smtpClient.Send(message);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
它可能是什么?
答案 0 :(得分:3)
添加后,它对我有用:
smtpClient.Port = 587;
smtpClient.EnableSsl = true;