コード例 #1
0
        public bool Send(EmailDto emailDto)
        {
            var result = true;

            try
            {
                foreach (var destination in emailDto.EmailAndTokenTo.Values)
                {
                    var mymsg = new EmailMessage("My Thai Star Restaurant booking stastus", "My Thai Star Restaurant", emailDto.EmailFrom, new List <string> {
                        destination
                    });

                    var body = PopulateEmailBody(emailDto, destination);


                    mymsg.AddBody(body, new List <string> {
                        GeFilePath("mui-email-inline.css"), GeFilePath("mui-email-styletag.css")
                    }, EmailBodyType.HtmlText);
                    mymsg.AddBody(body, new List <string>(), EmailBodyType.HtmlText);

                    var gmailMessageSender = new GoogleEmail();
                    gmailMessageSender.SendMessage(GmailServiceInstance, Credential.UserId, mymsg.GetEmailMessage());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message} : {ex.InnerException}");
                result = false;
            }

            return(result);
        }
コード例 #2
0
        public void ShouldSendEmailToTestProvider()
        {
            var message = new EmailMessage("*****@*****.**", "*****@*****.**")
            {
                Subject = "Hello world"
            };

            message.AddBody(EmailMessageBody.FromText("Hello world body"));
            message.AddBody(EmailMessageBody.FromHtml("Hello world body"));
            _provider.Send(message);

            _provider.HasMessageFrom("*****@*****.**").Should().BeTrue();
        }
コード例 #3
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();
        }
コード例 #4
0
            public async Task ShouldConfigureSpecifiedEmailLoggingProviderOnEmailProvider()
            {
                var factory         = new DefaultEmailProviderFactory(typeof(StubEmailProvider).AssemblyQualifiedName);
                var loggingProvider = new StubEmailLoggingProvider();

                factory.EmailLoggingProvider = loggingProvider;

                var provider = factory.GetEmailProvider();

                var emailMessage = new EmailMessage("*****@*****.**", "*****@*****.**")
                {
                    Subject = "Test"
                };

                emailMessage.AddBody(EmailMessageBody.FromText("test"));
                await provider.SendAsync(emailMessage);

                loggingProvider.LogCallCount.Should().Be(1);
            }
コード例 #5
0
        public async Task ShouldDeliverToPickupLocation()
        {
            var settings = new Mock <IPickupLocationProviderSettings>();

            settings.SetupGet(s => s.DisableDelivery).Returns(false);
            settings.SetupGet(s => s.Location).Returns(_tempDirectory.FullName);

            var provider = new PickupLocationProvider(settings.Object);
            var message  = new EmailMessage("*****@*****.**", "*****@*****.**")
            {
                Subject = "Unit test"
            };

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

            _tempDirectory.EnumerateFiles("*.eml", SearchOption.TopDirectoryOnly).Count().Should().Be(1);
            var emlFile    = _tempDirectory.EnumerateFiles("*.eml", SearchOption.TopDirectoryOnly).First();
            var emlContent = File.ReadAllText(emlFile.FullName);

            emlContent.Should().Contain("*****@*****.**");
            emlContent.Should().Contain("*****@*****.**");
            emlContent.Should().Contain("Unit test");
        }