Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29929

Send Email without Credential C# in .net Core Application

$
0
0

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]


Viewing all articles
Browse latest Browse all 29929

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>