Exemple #1
0
        private void SendErrorEmail(string file, AdminEmailConfiguration adminEmail, ProcessResult result)
        {
            if (result.Type != ResulType.PROCESS && adminEmail != null && adminEmail.HasErrorEmail && adminEmail.Emails.Count > 0)
            {
                _logger.Debug($"Send end process email for file {file}");

                var smtpClient = new SmtpClient(_configuration.SmtpHost, _configuration.SmtpPort);
                smtpClient.Credentials = new NetworkCredential(_configuration.AdminUser, _configuration.AdminPass);

                var mailMessage = new MailMessage()
                {
                    Subject = "DOPPLER RELAY PROCESS ERROR",
                    From    = new MailAddress("*****@*****.**", "Doppler Relay Support")
                };
                foreach (string email in adminEmail.Emails)
                {
                    mailMessage.To.Add(email);
                }
                string body = null;
                switch (result.Type)
                {
                case ResulType.DOWNLOAD:
                    body = File.ReadAllText($@"{AppDomain.CurrentDomain.BaseDirectory}\EmailTemplates\ErrorDownload.es.html");
                    break;

                case ResulType.LOGIN:
                    body = File.ReadAllText($@"{AppDomain.CurrentDomain.BaseDirectory}\EmailTemplates\ErrorLogin.es.html");
                    break;

                case ResulType.UNZIP:
                    body = File.ReadAllText($@"{AppDomain.CurrentDomain.BaseDirectory}\EmailTemplates\ErrorUnzip.es.html");
                    break;

                case ResulType.REPEATED:
                    body = File.ReadAllText($@"{AppDomain.CurrentDomain.BaseDirectory}\EmailTemplates\ErrorRepeated.es.html");
                    break;
                }

                if (string.IsNullOrEmpty(body))
                {
                    body = "Error processing file {0}.";
                }

                mailMessage.Body = string.Format(body, Path.GetFileName(file));

                try
                {
                    smtpClient.Send(mailMessage);
                }
                catch (Exception e)
                {
                    _logger.Error($"Error trying to send error process email -- {e}");
                }
            }
        }
 public DataTable GetConfiguration(AdminEmailConfiguration obj)
 {
     return(new AdminConfigurationBAL().GetConfiguration(obj));
 }