3
I am trying to use an account to send email, with my project in c#, using the namespace System.Net.Mail
, however I can’t authenticate on outlook server, it throws me the exception:
System.Net.Mail.Smtpexception: 'Mailbox not available. A server response was: 5.7.3 Requested action aborted; user not authenticated'
Follows 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;
}
}
Check your MS account security settings. You should probably allow some usage option.
– Aline