Exemplo n.º 1
0
        public static SendResult SendMessage(NotificationServiceSettings settings, Message message)
        {
            var container   = NotificationMessageContainer.Create(message);
            var client      = CreateSmtpClient(settings);
            var mailMessage = CreateEmailMessage(settings, container);

            try
            {
                client.Send(mailMessage);
                return(new SendResult());
            }
            catch (Exception e)
            {
                return(new SendResult(e));
            }
        }
Exemplo n.º 2
0
        private static MailMessage CreateEmailMessage(NotificationServiceSettings settings, NotificationMessageContainer messageContainer)
        {
            var userMapanger  = new AppUserManager(new AppUserStore(DbContext));
            var messageToSend = (EmailNotificationMessage)messageContainer.Message;
            var user          = userMapanger.FindById(messageContainer.UserId.Value);

            return(new MailMessage
            {
                From = new MailAddress(settings.SmtpCredentials.SmtpNotificationEmail, settings.SmtpCredentials.SmtpSenderName),
                To = { user.Email },
                Subject = messageToSend.Subject,
                Body = messageToSend.Body,
                IsBodyHtml = false
            });
        }