Ejemplo n.º 1
0
        public async Task SendMessageAsync <TMessage, TMessageContext>(TMessage message, TMessageContext context)
            where TMessage : Message
            where TMessageContext : IMessageContext
        {
            var sendMessageConfigModel = configProvider.ConfigurateSendMessageConfigModel();
            var fromEmail         = new MailAddress(sendMessageConfigModel.Email, message.Title);
            var fromEmailPassword = sendMessageConfigModel.Password;
            var toEmail           = new MailAddress(message.ToEmailAddress);

            using (var smtp = new SmtpClient())
            {
                smtp.Host        = sendMessageConfigModel.SmtpHost;
                smtp.Port        = sendMessageConfigModel.SmtpPort;
                smtp.EnableSsl   = true;
                smtp.Credentials = new NetworkCredential(fromEmail.Address, fromEmailPassword);
                var mailMessage = new MailMessage(fromEmail, toEmail)
                {
                    Subject    = message.Subject,
                    Body       = message.GetBody(context),
                    IsBodyHtml = true,
                };
                await smtp.SendMailAsync(mailMessage);
            }
        }