Send an Office365 SMTP mail in .NET/C#

Sending a mail using Office365 is no big deal. It is just similar to how you send a mail via any SMTP server. But you will have to mind the SMTP host, port number and remember to enable SSL in the code. Here goes the code snippet:

[code]
using (MailMessage message = new MailMessage())
{
message.From = new MailAddress(“praveen@YourO365Domain.com”);
message.To.Add(“praveen@yourmail.com”);
message.Subject = “test mail”;
message.Body = “<h1>test</h1>”;
message.IsBodyHtml = true;

SmtpClient client = new SmtpClient(“outlook.office365.com”, 587);

client.Credentials = new NetworkCredential(“praveen@YourO365Domain.com”, “passwordhere”);
client.EnableSsl = true;
client.Send(message);
}
[/code]