I am successfully able to send an email with a credential but if I am trying to send it without credential then getting error. Below is my sample code.
string to = "082asad@gmail.com"; string from = "asad.gilani@outlook.com"; MailMessage message = new MailMessage(from, to); message.Subject = "Using the new SMTP client."; message.Body = @"Using this new feature, you can send an email message from an application very easily."; NetworkCredential cred = new NetworkCredential("asad.gilani@outlook.com",""); SmtpClient client = new SmtpClient("smtp-mail.outlook.com", 587); client.EnableSsl = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = cred; try { client.Send(message); Console.WriteLine("Email Sent"); } catch (Exception ex) { Console.WriteLine("Exception caught in CreateTestMessage2(): {0}", ex.ToString()); }
I tried many things but not seem to be worked.I a getting errorThe SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [DX2P273CA0012.AREP273.PROD.OUTLOOK.COM]