Mail with Office 365

Nov 14, 2014 at 3:52 PM
Edited Nov 14, 2014 at 3:52 PM
I would like to send mail with my Office365 user,

I tried this but seem not run ...
        using (var cl = new SmtpClient("smtp.office365.com"))
        {
            cl.Port = 587;
            cl.EncryptedCommunication = SmtpEncryptedCommunication.Tls;
            cl.AuthenticateMode = SmtpAuthenticateMode.Auto;
            cl.UserName = "myuser";
            cl.Password = "mypassword";


            SmtpMessage mg = new SmtpMessage();
            mg.Subject = "2014/05/25 night";
            mg.BodyText = "Hi.I'll go Tokyo in next week.How about have dinner togegher?";
            mg.From = new MailAddress("me@me365.com");
            // set recipients
            mg.To.Add(new MailAddress("me@hotmail.com"));

            // set subject if necessary
            mg.Subject = "It is a sample mail";
            // set body if necessary
            mg.BodyText = "You can send these char";

            // send message
            SendMailResult rs = cl.SendMail(mg);
            if (rs.SendSuccessful == false)
            {
                Console.WriteLine("Success");
            }
        }
Coordinator
Nov 26, 2014 at 12:17 PM
Hi.

Can you execute this code against to GMail account?