private PostmarkMessage ConstructMessage(string inboundAddress, int number = 0)
        {
            var message = new PostmarkMessage()
            {
                From       = WRITE_TEST_SENDER_EMAIL_ADDRESS,
                To         = WRITE_TEST_SENDER_EMAIL_ADDRESS,
                Cc         = WRITE_TEST_EMAIL_RECIPIENT_ADDRESS,
                Bcc        = "*****@*****.**",
                Subject    = String.Format("Integration Test - {0} - Message #{1}", TESTING_DATE, number),
                HtmlBody   = String.Format("Testing the Postmark .net client, <b>{0}</b>", TESTING_DATE),
                TextBody   = "This is plain text.",
                TrackOpens = true,
                TrackLinks = LinkTrackingOptions.HtmlAndText,
                Headers    = new HeaderCollection()
                {
                    new MailHeader("X-Integration-Testing-Postmark-Type-Message", TESTING_DATE.ToString("o"))
                },
                ReplyTo = inboundAddress,
                Tag     = "integration-testing"
            };

            var content = "{ \"name\" : \"data\", \"age\" : null }";

            message.Attachments.Add(new PostmarkMessageAttachment()
            {
                ContentType = "application/json",
                Name        = "test.json",
                Content     = Convert.ToBase64String(Encoding.UTF8.GetBytes(content))
            });
            return(message);
        }
Esempio n. 2
0
        private TemplatedPostmarkMessage BuildTemplatedMessage(long templateId, string testValue)
        {
            var message = new TemplatedPostmarkMessage
            {
                TemplateId    = templateId,
                TemplateModel = new { testKey = $"{testValue}" },
                From          = WRITE_TEST_SENDER_EMAIL_ADDRESS,
                To            = WRITE_TEST_SENDER_EMAIL_ADDRESS,
                Headers       = new HeaderCollection
                {
                    new MailHeader("X-Integration-Testing-Postmark-Type-Message", TESTING_DATE.ToString("o"))
                },
                Metadata = new Dictionary <string, string> {
                    { "test-key", "test-value" }, { "client-id", "42" }
                },
                Tag = "integration-testing"
            };

            var content = "{ \"name\" : \"data\", \"age\" : null }";

            message.Attachments.Add(new PostmarkMessageAttachment
            {
                ContentType = "application/json",
                Name        = "test.json",
                Content     = Convert.ToBase64String(Encoding.UTF8.GetBytes(content))
            });
            return(message);
        }
        public async void Client_CanSendASingleMessage()
        {
            var result = await _client.SendMessageAsync(WRITE_TEST_SENDER_EMAIL_ADDRESS,
                                                        WRITE_TEST_EMAIL_RECIPIENT_ADDRESS,
                                                        String.Format("Integration Test - {0}", TESTING_DATE),
                                                        String.Format("Testing the Postmark .net client, <b>{0}</b>", TESTING_DATE)
                                                        , new Dictionary <string, string>()
            {
                { "X-Integration-Testing", TESTING_DATE.ToString("o") }
            });

            Assert.AreEqual(PostmarkStatus.Success, result.Status);
            Assert.AreEqual(0, result.ErrorCode);
            Assert.AreNotEqual(Guid.Empty, result.MessageID);
        }
        public async void Client_CanSearchTagTriggers()
        {
            var nameprefix = _triggerPrefix + "-tag-" + TESTING_DATE.ToString("o");
            var names      = Enumerable.Range(0, 10).Select(k => nameprefix + Guid.NewGuid()).ToArray();

            var awaitables = names.Select(name => _client.CreateTagTriggerAsync(name));
            var results    = await Task.WhenAll(awaitables);

            foreach (var name in names)
            {
                var result = (await _client.SearchTaggedTriggers(0, 100, name)).Tags;
                Assert.Equal(name, result.Single().MatchName);
            }

            var allTriggers = await _client.SearchTaggedTriggers();

            Assert.Equal(names.Count(), allTriggers.Tags.Count(k => k.MatchName.StartsWith(nameprefix)));
        }
Esempio n. 5
0
        public async void Client_CanSendASingleMessage_With_CC()
        {
            var result = await _client.SendMessageAsync(WRITE_TEST_SENDER_EMAIL_ADDRESS,
                                                        WRITE_TEST_EMAIL_RECIPIENT_ADDRESS,
                                                        String.Format("Integration Test - {0}", TESTING_DATE),
                                                        String.Format("Plain text body, {0}", TESTING_DATE),
                                                        String.Format("Testing the Postmark .net client, <b>{0}</b>", TESTING_DATE),
                                                        new Dictionary <string, string>()
            {
                { "X-Integration-Testing", TESTING_DATE.ToString("o") }
            },
                                                        new Dictionary <string, string>() {
                { "test-metadata", "value-goes-here" },
                { "more-metadata", "more-goes-here" }
            }, cc : WRITE_TEST_EMAIL_RECIPIENT_ADDRESS);

            Assert.Equal(PostmarkStatus.Success, result.Status);
            Assert.Equal(0, result.ErrorCode);
            Assert.NotEqual(Guid.Empty, result.MessageID);
        }