Beispiel #1
0
        public async Task ShouldSendEmailWithAttachmentUsingSmtp()
        {
            var provider = new SmtpClientProvider(_settings.Object);
            var message  = new EmailMessageWithAttachment("*****@*****.**", "*****@*****.**")
            {
                Subject = "Unit test"
            };

            message.AddBody(EmailMessageBody.FromText("Hello world"));
            var textStream = new MemoryStream();

            using (var wtr = new StreamWriter(textStream))
            {
                wtr.WriteLine("Hello world attachment");
                wtr.Flush();
                message.AddAttachment(EmailMessageAttachment.Create(textStream, Encoding.UTF8, "test.txt", "plain/text"));
                await provider.SendAsync(message);
            }

            _server.ReceivedEmailCount.Should().Be(1);
            var receivedMessage = _server.ReceivedEmail.First();

            receivedMessage.Subject.Should().Be("Unit test");
            receivedMessage.Body.Should().Be("Hello world");
            receivedMessage.IsBodyHtml.Should().BeFalse();

            receivedMessage.Attachments.Count.Should().Be(1);
            receivedMessage.Attachments.First().Name.Should().Be("test.txt");
            receivedMessage.Attachments.First().ContentType.MediaType.Should().Be("plain/text");
        }
Beispiel #2
0
        public async Task ShouldSendEmailUsingSmtp()
        {
            var provider = new SmtpClientProvider(_settings.Object);
            var message  = new EmailMessage("*****@*****.**", "*****@*****.**")
            {
                Subject = "Unit test"
            };

            message.AddBody(EmailMessageBody.FromText("Hello world"));
            await provider.SendAsync(message);

            _server.ReceivedEmailCount.Should().Be(1);
            var receivedMessage = _server.ReceivedEmail.First();

            receivedMessage.Subject.Should().Be("Unit test");
            receivedMessage.Body.Should().Be("Hello world");
            receivedMessage.IsBodyHtml.Should().BeFalse();
        }