try
{
MailMessage m = new MailMessage("testesmtpmi@hotmail.com", "myEmail@gmail.com", "Situação", "Oi, tudo bem?");
SmtpClient smtp = new SmtpClient("smtp.live.com", 587);
smtp.Credentials = new NetworkCredential("testesmtpmi@hotmail.com", "xxxx");
smtp.EnableSsl = true;
smtp.Send(m);
Console.WriteLine("sucesso");
}
catch (SmtpException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.ReadKey();
}
这里有什么不对吗? 它加入了catch并说发送电子邮件失败
答案 0 :(得分:0)
try
{
MailMessage m = new MailMessage("WindowsLiveUserName@live.com", "myEmail@gmail.com", "Situação", "Oi, tudo bem?");
SmtpClient smtp = new SmtpClient("smtp.live.com", 587);
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("WindowsLiveUserName@live.com", "YourPassword", "");
smtp.Send(m);
Console.WriteLine("sucesso");
}
catch (SmtpException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.ReadKey();
}