Пример #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 = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSOptional);

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

                TestSetup.AssertRecipientsInDeliveryQueue(0);

                server.WaitForCompletion();

                CustomAssert.IsTrue(server.MessageData.Contains("Test message"));
            }
        }
Пример #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 = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSRequired);

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

                TestSetup.AssertRecipientsInDeliveryQueue(0);

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

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

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