无法从 C# 应用程序发送邮件
Can't send mail from C# app
我正在尝试从我正在开发的应用程序发送邮件,但总是收到相同的异常消息:"Aditional Information: Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated"。
这是我的代码:
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;
}
在设置凭据之前尝试使用 UseDefaultCredentials = false
:
appClient.UseDefaultCredentials = false;
appClient.Credentials = Credentials;
我正在尝试从我正在开发的应用程序发送邮件,但总是收到相同的异常消息:"Aditional Information: Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated"。
这是我的代码:
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;
}
在设置凭据之前尝试使用 UseDefaultCredentials = false
:
appClient.UseDefaultCredentials = false;
appClient.Credentials = Credentials;