I'm trying to use an account to send email, with my project in C #, using namespace System.Net.Mail
, however I can not authenticate in the outlook server, it throws me the exception:
System.Net.Mail.SmtpException: 'Mailbox not available. THE response from the server was: 5.7.3 Requested action aborted; user not authenticated '
Follow my code:
private void Email()
{
SmtpClient client = new SmtpClient("smtp-mail.outlook.com");
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential("[email protected]", "minhasenha");
client.EnableSsl = true;
client.Credentials = credentials;
client.TargetName = "smtp-mail.outlook.com";
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]",string.Empty,System.Text.Encoding.UTF8);
mail.To.Add (new MailAddress("[email protected]"));
mail.Subject = "Teste de e-mail";
mail.Body = "Teste de e-mail";
client.Send(mail);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
}