Beispiel #1
0
 public void Execute(IJobExecutionContext context)
 {
     try {
         logger.Info(service.GetHello());
     }
     catch (EndpointNotFoundException e) {
         logger.LogException(LogLevel.Error, "Server is not responding", e);
     }
 }
Beispiel #2
0
        public bool SendEmail(EmailData emailData)
        {
            bool isOk = false;

            var fromAddressObj = new MailAddress(emailData.FromAddress, emailData.FromDisplayName ?? emailData.FromAddress);
            var toAddressObj   = new MailAddress(emailData.ToAddress, emailData.ToDisplayName ?? emailData.ToAddress);

            int MaxTryCount = 3;
            int tryCount    = 0;

            while (!isOk && tryCount < MaxTryCount)
            {
                try
                {
                    var smtp = new SmtpClient
                    {
                        Host                  = _configuration.AppSettings["SmtpHost"],
                        Port                  = _configuration.AppSettings["SmtpPort"].ToInt(),
                        EnableSsl             = true,
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials           = new NetworkCredential(_configuration.AppSettings["SmtpUsername"], _configuration.AppSettings["SmtpPassword"])
                    };

                    using (var message = new MailMessage(fromAddressObj, toAddressObj)
                    {
                        Subject = emailData.Subject,
                        Body = emailData.Body,
                    })
                    {
                        long size = 0;

                        smtp.Send(message);
                        isOk = true;
                    }

                    _logger.Info("Email was sent successfully");
                }
                catch (Exception exc)
                {
                    if (tryCount < MaxTryCount)
                    {
                        tryCount++;
                    }
                    else
                    {
                        _logger.Error("Error sending email report after {0} retries. Error: {1}",
                                      MaxTryCount,
                                      exc.Message);
                    }
                }
            }

            return(isOk);
        }