Example #1
0
        private EmailSenderConfiguration BuildTestConfiguration(ToConfiguration toConfiguration = null)
        {
            var configuration = new EmailSenderConfiguration();

            configuration.From.Name          = "Somebody";
            configuration.From.EmailAddress  = "*****@*****.**";
            configuration.SmtpServer         = "smtp.test.com";
            configuration.SmtpPort           = 25;
            configuration.Domain             = "someDomain.com";
            configuration.EmailFormat        = TextFormat.Text;
            configuration.SecureSocketOption = SecureSocketOptions.None;

            if (toConfiguration != null)
            {
                configuration.To = toConfiguration;
            }
            else
            {
                configuration.To.Subject      = "Hello";
                configuration.To.EmailAddress = "*****@*****.**";
                configuration.To.Name         = "some recipient";
            }

            configuration.EmailBody = "this is the body of the e-mail";

            return(configuration);
        }
Example #2
0
        public void DoSendToMultipleRecipients()
        {
            //Arrange
            MimeMessage resultMessage   = null;
            var         toConfiguration = new ToConfiguration
            {
                Subject    = "test subject",
                Recipients =
                {
                    { "*****@*****.**",  "Test User 1" },
                    { "*****@*****.**", "Test User 2" },
                    { "*****@*****.**", "Test User 3" }
                }
            };
            var configuration = BuildTestConfiguration(toConfiguration);

            _smtpClientMock.Setup(x => x.SendAsync(It.IsAny <MimeMessage>(), It.IsAny <CancellationToken>(), It.IsAny <ITransferProgress>()))
            .Returns(Task.Factory.StartNew(() => { }))
            .Callback <MimeMessage, CancellationToken, ITransferProgress>((message, token, transferProgress) => resultMessage = message);

            //Act
            _emailSender.SendEmailAsync(configuration).Wait();

            //Assert
            Assert.AreEqual(toConfiguration.Recipients.Count, resultMessage.To.Mailboxes.Count());
            Assert.AreEqual("*****@*****.**", resultMessage.To.Mailboxes.First().Address);
            Assert.AreEqual("*****@*****.**", resultMessage.To.Mailboxes.ToList()[1].Address);
        }
Example #3
0
        public void DoSendToCarbonCopies()
        {
            //Arrange
            MimeMessage resultMessage   = null;
            var         toConfiguration = new ToConfiguration
            {
                Subject              = "test subject",
                EmailAddress         = "*****@*****.**",
                CarbonCopyRecipients =
                {
                    { "*****@*****.**", "Name1" }
                }
            };
            var configuration = BuildTestConfiguration(toConfiguration);

            _smtpClientMock.Setup(x => x.SendAsync(It.IsAny <MimeMessage>(), It.IsAny <CancellationToken>(), It.IsAny <ITransferProgress>()))
            .Returns(Task.Factory.StartNew(() => { }))
            .Callback <MimeMessage, CancellationToken, ITransferProgress>((message, token, transferProgress) => resultMessage = message);

            //Act
            _emailSender.SendEmailAsync(configuration).Wait();

            //Assert
            Assert.AreEqual("*****@*****.**", resultMessage.Cc.Mailboxes.First().Address);
        }