How do I send an Email from a .NET Core App? Print

  • 0

To send an email from a .NET Core app, you can use the SmtpClient class in the System.Net.Mail namespace. Here's some sample code that demonstrates how to send an email using SmtpClient:

using System.Net; using System.Net.Mail; // Set up the email message var message = new MailMessage(); message.To.Add("[email protected]"); message.Subject = "Test Email"; message.Body = "This is a test email sent from a .NET Core app."; // Set up the SMTP client var smtpClient = new SmtpClient("issed-adaptive-mail-server"); smtpClient.Port = 25; smtpClient.UseDefaultCredentials = false; smtpClient.EnableSsl = true; smtpClient.Credentials = new NetworkCredential("[email protected]", "your-email-password"); // Send the email smtpClient.Send(message);

In this example, we create a new MailMessage object and set its To, Subject, and Body properties to specify the email's recipient, subject, and body. Then we create a new SmtpClient object and configure it with the SMTP server's host name, port number, SSL settings, and authentication credentials. Finally, we call the Send method of the SmtpClient object and pass in the MailMessage object to send the email. Note that you'll need to replace "[email protected]" and "your-email-password" with your actual email address and password.


Was this answer helpful?

« Back