Thanks, but there seems to be missing steps in this example solution.
eg there's no Startup.cs file in the Demo install (and I don't know what it is anyway :) )
And I don't use SendGrid - just a normal SMTP email server setup is enough for me now.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In .net framework its easy to add SMTP email services to an app via the _AppStart file.
Now that I'm trailling Core 7 - how do I add email to the Demo app?
Most of the guidance on the net applies to a Core API which is irrelevant as I'm just doing a simple Core App via the Add new Proejct - ASP.NET Core Web app template.
Thanks, but there seems to be missing steps in this example solution.
eg there's no Startup.cs file in the Demo install (and I don't know what it is anyway :) )
And I don't use SendGrid - just a normal SMTP email server setup is enough for me now.
Use .NET SmptClient class as shown below
using Microsoft.AspNetCore.Identity.UI.Services;
using System.Net;
using System.Net.Mail;
using System.Threading.Tasks;
namespace YourProject.Services
{
public class EmailSender : IEmailSender
{
public Task SendEmailAsync(string email, string subject, string htmlMessage)
{
SmtpClient client = new SmtpClient
{
Port = 587,
Host = "smtp.gmail.com", //or another email sender provider
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("your email sender", "password")
};
return client.SendMailAsync("your email sender", email, subject, htmlMessage);
}
}
}
In min api apps, program.cs is the startup file.