How to add smtp hotmail account to send mail

I wrote some codes to send email, but I can send mail from gmail account to gmail account also, I want to use hotmail accounts, how can I do that? thanks to

SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("xxx@gmail.com");
mail.To.Add("kalaylevent@gmail.com");
mail.Subject = "Test Mail - 1";
mail.IsBodyHtml = true;
string htmlBody;
htmlBody = "Write some HTML code here";
mail.Body = htmlBody;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("kalaylevent@gmail.com", "mypassword");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);

      

+2


source to share


1 answer


I modified the code a bit and experienced success (Hotmail to Gmail)



SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
var mail = new MailMessage();
mail.From = new MailAddress("youremail@hotmail.com");
mail.To.Add("to@gmail.com");
mail.Subject = "Test Mail - 1";
mail.IsBodyHtml = true;
string htmlBody;
htmlBody = "Write some HTML code here";
mail.Body = htmlBody;
SmtpServer.Port = 587;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("youremail@hotmail.com", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);

      

+20


source







All Articles