Ejemplo n.º 1
0
 public void SendEmail(SendEmailCommand command)
 {
     EnsureIsValid(command);
     try
     {
         var message = new SendGridMessage
         {
             From = command.From,
             To = command.To.ToArray(),
             Subject = command.Subject,
             Text = command.Text
         };
         var client = _deps.SendGridClientFactory.CreateWebClient();
         client.Deliver(message);
     }
     catch (Exception ex)
     {
         throw new ServiceException("Can't send email.", ex);
     }
 }
Ejemplo n.º 2
0
 public void Log(SmsModel sms)
 {
     _logger.Info("Going to send following sms message: {0}", sms);
     if (_settings.EmailAddresses.Count == 0)
     {
         _logger.Warn("No email addresses are configured for email logger.");
         return;
     }
     var emailBuilder = new StringBuilder();
     emailBuilder.AppendFormat("From: {0}", sms.From).AppendLine()
                 .AppendFormat("To:   {0}", sms.To).AppendLine()
                 .AppendFormat("Text: {0}", sms.Text).AppendLine();
     var email = new SendEmailCommand
     {
         From = new MailAddress("*****@*****.**", "SMS Logger"),
         Subject = string.Format("New SMS for {0}", sms.To),
         Text = emailBuilder.ToString()
     };
     foreach (var emailAddress in _settings.EmailAddresses)
     {
         email.To.Add(emailAddress);
     }
     _emailService.SendEmail(email);
 }