//[Ignore("This test sends two real emails.")]
        public void Can_send_batched_messages()
        {
            var postmark = new PostmarkClient(_serverToken);

            var first = new PostmarkMessage
            {
                To       = _to,
                From     = _from, // This must be a verified sender signature
                Subject  = Subject,
                TextBody = TextBody,
                HtmlBody = HtmlBody
            };
            var second = new PostmarkMessage
            {
                To       = _to,
                From     = _from, // This must be a verified sender signature
                Subject  = Subject,
                TextBody = TextBody,
                HtmlBody = HtmlBody
            };

            var responses = postmark.SendMessages(first, second);

            Assert.AreEqual(2, responses.Count());

            foreach (var response in responses)
            {
                Assert.IsNotNull(response);
                Assert.IsNotNullOrEmpty(response.Message);
                Assert.IsTrue(response.Status == PostmarkStatus.Success);
                Console.WriteLine("Postmark -> {0}", response.Message);
            }
        }
Esempio n. 2
0
        private bool SendBatch(IList <EmailMessage> payload)
        {
            var pm        = payload.Select(CreatePostmarkMessage).ToList();
            var responses = _client.SendMessages(pm).ToList();

            for (var i = 0; i < responses.Count(); i++)
            {
                payload[i].DeliveryAttempts++;
                if (responses[i].Status != PostmarkStatus.Success)
                {
                    continue;
                }
                payload[i].Delivered   = true;
                payload[i].DeliveredAt = DateTime.Now;
            }
            return(responses.All(r => r.Status == PostmarkStatus.Success));
        }