简体   繁体   中英

Sending email using System.Net.Mail and outlook.com

Code:

MailMessage mail = new MailMessage("name@hotmail.com", "name@hotmail.com");
            SmtpClient client = new SmtpClient();
            client.Port = 587;
            client.Host = "smtp-mail.outlook.com";
            client.EnableSsl = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential("name@hotmail.com", "password");

            mail.Subject = "this is a test email.";
            mail.Body = "this is my test email body";
            client.Send(mail);

Error message: Exception: Failure sending message. InnerException: Unable to connect to remote server. A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond 65.55.176.126:587

I am able to login into the account using the browser. What am I missing here?

Switched to smtp.gmail.com and it worked. I will let Microsoft solve this for the future!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM