Here is an example of how you can send an email using SMTP in .NET Core with C#:
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
public class EmailService
{
public async Task SendEmailAsync(string email, string subject, string message)
{
var smtpClient = new SmtpClient("smtp.example.com")
{
Port = 587,
Credentials = new NetworkCredential("[email protected]", "password"),
EnableSsl = true,
};
await smtpClient.SendMailAsync("[email protected]", email, subject, message);
}
}
In this example, replace "smtp.example.com"
, "[email protected]"
, and "password"
with your actual SMTP server details. The SendEmailAsync
method takes the recipient’s email, the subject of the email, and the message as parameters.
Please note that sending email synchronously can block your application while the email is being sent. It’s recommended to send email asynchronously, as shown in this example, to avoid blocking your application.