我尝试使用以下代码发送电子邮件时出现以下错误,如果错了,有人可以纠正我吗?
public async static Task SendEmailAsync(string email, string subject, string message)
{
try
{
var _email = "myemail@hotmail.com";
var epass = ConfigurationManager.AppSettings["mypassword"];
var _dispName = "Blog";
MailMessage myMessage = new MailMessage();
myMessage.To.Add(email);
myMessage.From = new MailAddress(_email, _dispName);
myMessage.Subject = subject;
myMessage.Body = message;
myMessage.IsBodyHtml = true;
using (SmtpClient smtp = new SmtpClient())
{
smtp.EnableSsl = true;
smtp.Host = "smtp.live.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(_email, epass);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.SendCompleted += (s, e) => { smtp.Dispose(); };
await smtp.SendMailAsync(myMessage);
}
}
catch (Exception ex)
{
throw ex;
}
}
服务器响应是:
5.7.3 Requested action aborted; user not authenticated