我尝试从我正在开发的应用发送邮件,但始终收到相同的异常消息:"其他信息:邮箱不可用。服务器响应为:5.7.3请求的操作中止;用户未经过身份验证"。
这是我的代码:
SmtpClient appClient = new SmtpClient("smtp-mail.outlook.com");
appClient.Port = 587;
appClient.DeliveryMethod = SmtpDeliveryMethod.Network;
appClient.UseDefaultCredentials = false;
System.Net.NetworkCredential Credentials =
new System.Net.NetworkCredential(Properties.Settings.Default.systemMail,
Properties.Settings.Default.systemMailPass);
appClient.EnableSsl = true;
appClient.Credentials = Credentials;
try
{
var mail = new MailMessage(Properties.Settings.Default.systemMail.Trim(), usrMail.Trim());
mail.Subject = "Usuario ha sido creado con éxito";
mail.Body = "Se ha creado el usuario " + usrCode + " en el servidor: " + Properties.Settings.Default.serverAdress + " instancia: " + Properties.Settings.Default.serverInstance + ".";
appClient.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
答案 0 :(得分:2)
在设置凭据之前尝试使用UseDefaultCredentials = false
:
appClient.UseDefaultCredentials = false;
appClient.Credentials = Credentials;