Send email hotmail asp.net

Here is an example of how to send an email using Hotmail (Outlook.com) in an ASP.NET application:

Using System.Net.Mail

You can use the System.Net.Mail namespace to send an email in ASP.NET. Here is an example:

using System.Net.Mail;

// Create a new MailMessage object
MailMessage mail = new MailMessage();

// Set the sender's email address
mail.From = new MailAddress("[email protected]");

// Set the recipient's email address
mail.To.Add("[email protected]");

// Set the subject of the email
mail.Subject = "Test email from ASP.NET";

// Set the body of the email
mail.Body = "This is a test email sent from ASP.NET";

// Create a new SmtpClient object
SmtpClient client = new SmtpClient();

// Set the SMTP server and port
client.Host = "smtp.live.com";
client.Port = 587;

// Set the username and password for the SMTP server
client.Credentials = new NetworkCredential("[email protected]", "your_password");

// Send the email
client.Send(mail);

Using System.Net.Mail.SmtpClient

You can also use the SmtpClient class directly to send an email. Here is an example:

using System.Net.Mail;

// Create a new SmtpClient object
SmtpClient client = new SmtpClient();

// Set the SMTP server and port
client.Host = "smtp.live.com";
client.Port = 587;

// Set the username and password for the SMTP server
client.Credentials = new NetworkCredential("[email protected]", "your_password");

// Create a new MailMessage object
MailMessage mail = new MailMessage();

// Set the sender's email address
mail.From = new MailAddress("[email protected]");

// Set the recipient's email address
mail.To.Add("[email protected]");

// Set the subject of the email
mail.Subject = "Test email from ASP.NET";

// Set the body of the email
mail.Body = "This is a test email sent from ASP.NET";

// Send the email
client.Send(mail);

Note: Make sure to replace [email protected] and your_password with your actual Hotmail (Outlook.com) email address and password.

Also, you need to enable less secure apps in your Hotmail (Outlook.com) account settings to allow ASP.NET to send emails on your behalf. You can do this by following these steps:

  1. Sign in to your Hotmail (Outlook.com) account.
  2. Click on your profile picture or initial in the top right corner, and then click on "Settings".
  3. Click on "Account" and then click on "Security".
  4. Scroll down to the "App passwords" section and click on "Generate".
  5. Enter a name for the app password, such as "ASP.NET Emailer".
  6. Click on "Generate" to generate the app password.
  7. Copy the app password and use it in your ASP.NET code instead of your regular password.