How do I send an email using ASP.NET? Print

  • 0

You can send an email using ASP.NET 4.8 by using the System.Net.Mail namespace. Here is an example code snippet in C#:

using System.Net.Mail; // Set up the email message MailMessage message = new MailMessage(); message.From = new MailAddress("[email protected]"); message.To.Add(new MailAddress("[email protected]")); message.Subject = "Test Email"; message.Body = "This is a test email sent from ASP.NET"; // Set up the SMTP client SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.example.com"; // your SMTP server smtp.Port = 25; // your SMTP port smtp.EnableSsl = true; // enable SSL if required smtp.Credentials = new System.Net.NetworkCredential("username", "password"); // your SMTP login credentials // Send the email smtp.Send(message);

In this example, you will need to replace the placeholders with your own email addresses, SMTP server details, and login credentials. Additionally, this example assumes that you have already configured your SMTP server settings in your ASP.NET application.


Was this answer helpful?

« Back