How to send email through office 365 outlook account programatically?
I tried with below code to send a custom email but getting exception on first line,
Code
SmtpClient mailClient = new SmtpClient("smtp.office365.com");
mailClient.Port = 587;
mailClient.EnableSsl = true;
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("username@domain.com", "password");
mailClient.Credentials = cred;
MailMessage message = new MailMessage();
message.From = new MailAddress("username@domain.com", "DisplayName");
message.To.Add("username@domain.com");
message.Subject = "Test subject";
message.Body = "Test body";
mailClient.Send(message);
Is there any way to send custom mail from office 365?