I am using send mail from office365 as below code
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress("*******", "*********"));
msg.From = new MailAddress("******", "*******");
msg.Subject = "This is a Test Mail";
msg.Body = "This is a test message using Exchange OnLine";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("******", "********");
client.Port = 587; // You can use Port 25 if 587 is blocked (mine is!)
client.Host = "d*******.mail.protection.outlook.com";//"smtp.office365.com";//
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;
client.Send(msg);
When I used smtp.office365.com
then I got below issue
The 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 [BM1PR01CA0089.INDPRD01.PROD.OUTLOOK.COM]
and if I use d**********.mail.protection.outlook.com
then I got
Unable to read data from the transport connection: net_io_connectionclosed.