How to add smtp hotmail account to send mail

I wrote some codes so as to send e mail but I can only send mail from gmail account to gmail account also, I want to use hotmail accounts how can i do it? thanks
It is

SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="176f6f6f57707a767e7b3974787a">[email protected]</a>");
mail.To.Add("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4bfb5b8b5adb8b1a2b1baa094b3b9b5bdb8fab7bbb9">[email protected]</a>");
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("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="600b010c01190c0516050e1420070d01090c4e030f0d">[email protected]</a>", "mypassword");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I changed a little of code and it tested successfully (from Hotmail to Gmail)

SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
var mail = new MailMessage();
mail.From = new MailAddress("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f881978d8a9d95999194b890978c95999194d69b9795">[email protected]</a>");
mail.To.Add("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="394d56795e54585055175a5654">[email protected]</a>");
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("<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="532a3c2621363e323a3f133b3c273e323a3f7d303c3e">[email protected]</a>", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x