当前位置: 首页>>代码示例>>C#>>正文


C# Client.SendMessageAsync方法代码示例

本文整理汇总了C#中Client.SendMessageAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Client.SendMessageAsync方法的具体用法?C# Client.SendMessageAsync怎么用?C# Client.SendMessageAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Client的用法示例。


在下文中一共展示了Client.SendMessageAsync方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestSendMessageInvalidDomainAsync

        public async Task TestSendMessageInvalidDomainAsync()
        {
            var client = new Client(ApiKey) { BaseUri = "http://0.0.0.0/" };

            var threwException = false;
            try
            {
                var message = new Message.Message
                {
                    Uid = Guid.NewGuid().ToString(),
                    Recipient = new Recipient("[email protected]"),
                    RecipientOverride = RecipientOverride,
                    Text = "This is my text content"
                };

                await client.SendMessageAsync(message);
            }
            catch (PostageResponseException<MessageResponse> exception)
            {
                threwException = true;
                Assert.IsNull(exception.ResponseContainer);
            }

            Assert.IsTrue(threwException);
        }
开发者ID:postageapp,项目名称:postageapp-net,代码行数:25,代码来源:ClientTest.cs

示例2: SendMessageAsyncTest

        public void SendMessageAsyncTest()
        {
            var client = new Client();
            RequestMessage testMessage = RequestMessage.CreateAccessRequest(TestFileName);

            ResponseMessage responseMessage = client.SendMessageAsync(testMessage).Result;

            Assert.AreEqual(ExpectedResponseMessage, responseMessage);
        }
开发者ID:RavingRabbit,项目名称:Labs,代码行数:9,代码来源:CommunicationTests.cs

示例3: TestGetMessageReceiptSuccessAsync

        public async Task TestGetMessageReceiptSuccessAsync()
        {
            var client = new Client(ApiKey);

            var message = new Message.Message
            {
                Uid = Guid.NewGuid().ToString(),
                Recipient = new Recipient("[email protected]"),
                RecipientOverride = RecipientOverride,
                Text = "This is my text content"
            };

            var sendResponseContainer = await client.SendMessageAsync(message);

            var responseContainer = await client.GetMessageReceiptAsync(sendResponseContainer.Response.Uid);

            Assert.AreEqual(ResponseStatus.Ok, responseContainer.Response.Status);
            Assert.AreEqual(sendResponseContainer.Data.Id, responseContainer.Data.Id);
        }
开发者ID:postageapp,项目名称:postageapp-net,代码行数:19,代码来源:ClientTest.cs

示例4: TestSendMessageWithAttachmentAsync

        public async Task TestSendMessageWithAttachmentAsync()
        {
            var client = new Client(ApiKey);

            var fileContent = "file contents!\n\n";

            var contentBytes = Encoding.UTF8.GetBytes(fileContent);
            var stream = new MemoryStream(contentBytes);

            var message = new Message.Message
            {
                Uid = Guid.NewGuid().ToString(),
                Subject = "Has attachment",
                Recipient = new Recipient("[email protected]"),
                RecipientOverride = RecipientOverride,
                Text = "This email should have an attachment",
            };

            message.Attachments.Add(new Attachment(stream, "readme.txt", "text/plain"));

            var responseContainer = await client.SendMessageAsync(message);

            Assert.AreEqual(ResponseStatus.Ok, responseContainer.Response.Status);
        }
开发者ID:postageapp,项目名称:postageapp-net,代码行数:24,代码来源:ClientTest.cs

示例5: TestSendMessageWithHtmlContentAsync

        public async Task TestSendMessageWithHtmlContentAsync()
        {
            var client = new Client(ApiKey);

            var responseContainer = await client.SendMessageAsync(new Message.Message
                {
                    Uid = Guid.NewGuid().ToString(),
                    Subject = "Html body",
                    Recipient = new Recipient("[email protected]"),
                    RecipientOverride = RecipientOverride,
                    Text = "This email should have some html content.",
                    Html = "<h1>Title</h1><p>This is an <em>html email</em></p></h1>"
                });

            Assert.AreEqual(ResponseStatus.Ok, responseContainer.Response.Status);
        }
开发者ID:postageapp,项目名称:postageapp-net,代码行数:16,代码来源:ClientTest.cs

示例6: TestSendMessageWithHeadersAsync

        public async Task TestSendMessageWithHeadersAsync()
        {
            var client = new Client(ApiKey);
            var message = new Message.Message
                {
                    Uid = Guid.NewGuid().ToString(),
                    Recipient = new Recipient("[email protected]"),
                    RecipientOverride = RecipientOverride,
                    Text = "This email should have a custom from name and subject line."
                };

            message.Headers.Add("From", "[email protected]");
            message.Headers.Add("Subject", "This is a custom subject line");

            var responseContainer = await client.SendMessageAsync(message);

            Assert.AreEqual(ResponseStatus.Ok, responseContainer.Response.Status);
        }
开发者ID:postageapp,项目名称:postageapp-net,代码行数:18,代码来源:ClientTest.cs

示例7: TestSendMessageUidRoundTripAsync

        public async Task TestSendMessageUidRoundTripAsync()
        {
            var uid = Guid.NewGuid().ToString();

            var client = new Client(ApiKey);

            var responseContainer = await client.SendMessageAsync(new Message.Message
            {
                Uid = uid,
                Subject = "Specific Uid: " + uid,
                Text = "This email should have a specific uid",
                Recipient = new Recipient("[email protected]"),
                RecipientOverride = RecipientOverride
            });

            Assert.AreEqual(ResponseStatus.Ok, responseContainer.Response.Status);
            Assert.AreEqual(uid, responseContainer.Response.Uid);
        }
开发者ID:postageapp,项目名称:postageapp-net,代码行数:18,代码来源:ClientTest.cs

示例8: TestSendMessagePreconditionFailedAsync

        public async Task TestSendMessagePreconditionFailedAsync()
        {
            var client = new Client(ApiKey);

            var threwException = false;
            try
            {
                await client.SendMessageAsync(new Message.Message { Template = "some-unknown-template-xxxxxxxxxxxxxx" });
            }
            catch (PostageResponseException<MessageResponse> exception)
            {
                threwException = true;
                Assert.AreEqual(ResponseStatus.PreconditionFailed, exception.ResponseContainer.Response.Status);
            }

            Assert.IsTrue(threwException);
        }
开发者ID:postageapp,项目名称:postageapp-net,代码行数:17,代码来源:ClientTest.cs

示例9: TestSendMessageUnauthorizedAsync

        public async Task TestSendMessageUnauthorizedAsync()
        {
            var client = new Client("abc123ThisIsNotValid");

            var threwException = false;
            try
            {
                await client.SendMessageAsync(new Message.Message());
            }
            catch (PostageResponseException<MessageResponse> exception)
            {
                threwException = true;
                Assert.AreEqual(ResponseStatus.Unauthorized, exception.ResponseContainer.Response.Status);
            }

            Assert.IsTrue(threwException);
        }
开发者ID:postageapp,项目名称:postageapp-net,代码行数:17,代码来源:ClientTest.cs

示例10: TestSendMessageBadRequestAsync

        public async Task TestSendMessageBadRequestAsync()
        {
            var client = new Client(ApiKey);

            var threwException = false;
            try
            {
                await client.SendMessageAsync(new Message.Message());
            }
            catch (PostageResponseException<MessageResponse> exception)
            {
                threwException = true;
                Assert.AreEqual(ResponseStatus.BadRequest, exception.ResponseContainer.Response.Status);
            }

            Assert.IsTrue(threwException);
        }
开发者ID:postageapp,项目名称:postageapp-net,代码行数:17,代码来源:ClientTest.cs


注:本文中的Client.SendMessageAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。