using Microsoft.Extensions.Options; using SendGrid; using SendGrid.Helpers.Mail; using System.Threading.Tasks; namespace WebApp1.Services { public class AuthMessageSender : IEmailSender, ISmsSender { public AuthMessageSender(IOptions optionsAccessor) { Options = optionsAccessor.Value; } public AuthMessageSenderOptions Options { get; } //set only via Secret Manager public Task SendEmailAsync(string email, string subject, string message) { // Plug in your email service here to send an email. 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); } public Task SendSmsAsync(string number, string message) { // Plug in your SMS service here to send a text message. return Task.FromResult(0); } } }