using Microsoft.Extensions.Options; using SendGrid; using SendGrid.Helpers.Mail; using System.Threading.Tasks; namespace WebPW.Services { public class EmailSender : IEmailSender { public EmailSender(IOptions optionsAccessor) { Options = optionsAccessor.Value; } public AuthMessageSenderOptions Options { get; } //set only via Secret Manager public Task SendEmailAsync(string email, string subject, string message) { return Execute(Options.SendGridKey, subject, message, email); } public Task Execute(string apiKey, string subject, string message, string email) { var client = new SendGridClient(apiKey); var msg = new SendGridMessage() { From = new EmailAddress("Joe@contoso.com", "Joe Smith"), Subject = subject, PlainTextContent = message, HtmlContent = message }; msg.AddTo(new EmailAddress(email)); return client.SendEmailAsync(msg); } } }