您的位置:首页 > 汽车 > 时评 > EmailSender : IEmailSender

EmailSender : IEmailSender

2024/11/17 16:17:25 来源:https://blog.csdn.net/GZM888888/article/details/141474860  浏览:    关键词:EmailSender : IEmailSender

目录

一、EmailSender : IEmailSender

二、EmailSender : IEmailSender

三、EmailSender : IEmailSender

四、EmailSender : IEmailSender


一、EmailSender : IEmailSender

namespace WebPWrecover.Services
{
    public class EmailSender : IEmailSender
    {
        public EmailSender(IOptions<AuthMessageSenderOptions> optionsAccessor, ILogger<EmailSender> logger)
        {
            Options = optionsAccessor.Value;
            _logger = logger;
        }

二、EmailSender : IEmailSender

        public AuthMessageSenderOptions Options { get; }

        private readonly ILogger _logger;

        public async Task SendEmailAsync(string toEmail, string subject, string message)
        {
            if (string.IsNullOrEmpty(Options.SendGridKey))
            {
                throw new Exception("Null SendGridKey");
            }
            await Execute(Options.SendGridKey, subject, message, toEmail);
        }

三、EmailSender : IEmailSender

        public async Task Execute(string apiKey, string subject, string message, string toEmail)
        {
            var client = new SendGridClient(apiKey);
            var msg = new SendGridMessage()
            {
                From = new EmailAddress("jsolanoe@ucenfotec.ac.cr", "Autentificación de cuenta"),
                Subject = subject,
                PlainTextContent = message,
                HtmlContent = message
            };

四、EmailSender : IEmailSender


            msg.AddTo(new EmailAddress(toEmail));

            msg.SetClickTracking(false, false);
            var response = await client.SendEmailAsync(msg);
            _logger.LogInformation(response.IsSuccessStatusCode
                ? $"Email to {toEmail} queued successfully!"
                : $"Failure Email to {toEmail}");
        }
    }
}
 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com