예제 #1
0
        public async Task <MailMessageStatus> Send(MailMessage message)
        {
            MailMessageStatus result = new MailMessageStatus();

            if (String.IsNullOrEmpty(message.From))
            {
                message.From = _options.From;
            }

            message.Cc += $";{_options.CcRecipients}";

            message.Bcc += $";{_options.BccRecipients}";

            var response = await _client.PostAsync("", JsonContent(message));

            string content = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                result = JsonConvert.DeserializeObject <MailMessageStatus>(content);
            }
            else
            {
                result.Status = $"error {content}";
            }

            return(result);
        }
예제 #2
0
        public Task <MailMessageStatus> Send(MailMessage message)
        {
            _logger.LogInformation($"Logged message [{message.Subject}] to ${message.To}");

            var status = new MailMessageStatus
            {
                ReferenceId = Guid.NewGuid().ToString("N"),
                MessageId   = message.MessageId,
                Timestamp   = DateTime.UtcNow,
                Status      = "pending"
            };

            _store.Add(status);

            // cleanup
            var expired = _store.OrderByDescending(s => s.Timestamp).Skip(20).ToArray();

            foreach (var s in expired)
            {
                _store.Remove(s);
            }

            return(Task.FromResult(status));
        }