Esempio n. 1
0
        public void SmtpServerSupportingStartTls_StartTlsOptional()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Set up a server listening on port 250 which accepts email for [email protected]
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSRequired))
            {
                server.SetCertificate(SslSetup.GetCertificate());
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSOptional);

                var smtpClient = new SmtpClientSimulator();
                smtpClient.Send(account.Address, "*****@*****.**", "Test", "Test message");

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                server.WaitForCompletion();

                Assert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Esempio n. 2
0
        public void SmtpServerNOTSupportingStartTls_StartTlsRequired()
        {
            Account account = SingletonProvider <TestSetup> .Instance.AddAccount(_domain, "*****@*****.**", "test");

            // Set up a server listening on port 250 which accepts email for [email protected]
            var deliveryResults = new Dictionary <string, int>();

            deliveryResults["*****@*****.**"] = 250;

            int smtpServerPort = TestSetup.GetNextFreePort();

            using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone))
            {
                server.SetCertificate(SslSetup.GetCertificate());
                server.AddRecipientResult(deliveryResults);
                server.StartListen();

                Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSRequired);

                var smtpClient = new SmtpClientSimulator();
                smtpClient.Send(account.Address, "*****@*****.**", "Test", "Test message");

                CustomAsserts.AssertRecipientsInDeliveryQueue(0);

                // This should now be processed via the rule -> route -> external server we've set up.
                server.WaitForCompletion();

                var msg = Pop3ClientSimulator.AssertGetFirstMessageText("*****@*****.**", "test");

                Assert.IsTrue(msg.Contains("Server does not support STARTTLS"));
            }
        }