Exemplo n.º 1
0
        public Task SendEmailAsync(CountryKind country, DateTime time, IEmailTemplate template)
        {
            return(Task.Run(() =>
            {
                if (template == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(template.ReceipentEmail))
                {
                    _logger?.WriteToErrorLogAsync(country, time, _workerKind, new Exception("template.ReceipentEmail is null or empty."));
                    return;
                }

                if (_smtpInfo == null)
                {
                    _logger?.WriteToErrorLogAsync(country, time, _workerKind, new Exception("SMTPInfo is emtpy so email can't be sent."));
                    return;
                }

                try
                {
                    SmtpClient client = new SmtpClient(_smtpInfo.SMTPServer, _smtpInfo.SMTPTCPPort)
                    {
                        Credentials = new NetworkCredential(_smtpInfo.SenderEmail, _smtpInfo.SenderPassword),
                        EnableSsl = true
                    };

                    MailMessage body = new MailMessage(_smtpInfo.SenderEmail, template.ReceipentEmail, template.Subject, template.HtmlContent)
                    {
                        IsBodyHtml = true,
                        BodyEncoding = Encoding.UTF8
                    };

                    client.SendAsync(body, null);
                    _logger.WriteToEmailLogAsync(country, time, _workerKind, template.HtmlContent);
                }
                catch (Exception ex)
                {
                    _logger?.WriteToErrorLogAsync(country, time, _workerKind, ex);
                }
            }));
        }
        public Task SendEmailAsync(CountryKind country, DateTime time, IEmailTemplate template)
        {
            if (template == null)
            {
                return(Task.CompletedTask);
            }

            try
            {
                BackTestBuySellRecord record = JsonConvert.DeserializeObject <BackTestBuySellRecord>(template.HtmlContent);
                _records.Add(record);
            }
            catch (Exception ex)
            {
                _logger?.WriteToErrorLogAsync(country, time, "BackTestNotificationService", ex);
            }

            return(Task.CompletedTask);
        }