Example #1
0
        public void TestSMTPClientTimeout()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            Dictionary <string, int> deliveryResults = new Dictionary <string, int>();

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

            SMTPServerSimulator server = new SMTPServerSimulator(1, 250);

            server.AddRecipientResult(deliveryResults);
            server.SimulatedError = SimulatedErrorType.Sleep15MinutesAfterSessionStart;
            server.SecondsToWaitBeforeTerminate = 20 * 60;
            server.StartListen();

            // Add a route so we can connect to localhost.
            hMailServer.Route route = AddRoutePointingAtLocalhost(5, 250, false);
            route.RelayerRequiresAuth = true;
            route.RelayerAuthUsername = "******";
            route.SetRelayerAuthPassword("MySecretPassword");

            // Send message to this route.
            SMTPClientSimulator smtp       = new SMTPClientSimulator();
            List <string>       recipients = new List <string>();

            recipients.Add("*****@*****.**");
            Assert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Test message"));

            // Wait for the client to disconnect.
            server.WaitForCompletion();

            Utilities.AssertRecipientsInDeliveryQueue(0);
        }
Example #2
0
        public bool SaveData()
        {
            if (_representedObject == null)
            {
                hMailServer.Settings settings = APICreator.Application.Settings;
                hMailServer.Routes   routes   = settings.Routes;
                _representedObject = routes.Add();

                Marshal.ReleaseComObject(settings);
                Marshal.ReleaseComObject(routes);
            }

            _representedObject.DomainName     = textDomainName.Text;
            _representedObject.Description    = textDescription.Text;
            _representedObject.TargetSMTPHost = textTargetSMTPHost.Text;
            _representedObject.TargetSMTPPort = textTargetSMTPPort.Number;

            _representedObject.ConnectionSecurity = (eConnectionSecurity)comboConnectionSecurity.SelectedValue;

            _representedObject.TreatSenderAsLocalDomain    = radioTreatSenderAsLocalDomain.Checked;
            _representedObject.TreatRecipientAsLocalDomain = radioTreatRecipientAsLocalDomain.Checked;

            _representedObject.NumberOfTries     = textNumberOfTries.Number;
            _representedObject.MinutesBetweenTry = textNumberOfMinutesBetween.Number;

            _representedObject.RelayerRequiresAuth = checkServerRequiresAuth.Checked;
            _representedObject.RelayerAuthUsername = textUsername.Text;


            if (textPassword.Dirty)
            {
                _representedObject.SetRelayerAuthPassword(textPassword.Password);
            }

            _representedObject.AllAddresses = radioRouteForAll.Checked;

            _representedObject.Save();

            // Set the object to clean.
            DirtyChecker.SetClean(this);

            Utility.RefreshNode(_representedObject.DomainName);

            return(true);
        }
        internal hMailServer.Route AddRoutePointingAtLocalhostWithAuth(int numberOfTries, int port)
        {
            // Add a route pointing at localhost
            hMailServer.Settings oSettings = SingletonProvider <Utilities> .Instance.GetApp().Settings;

            hMailServer.Route route = oSettings.Routes.Add();
            route.DomainName          = "dummy-example.com";
            route.TargetSMTPHost      = "localhost";
            route.TargetSMTPPort      = port;
            route.NumberOfTries       = numberOfTries;
            route.RelayerRequiresAuth = true;
            route.RelayerAuthUsername = GetUsername();
            route.SetRelayerAuthPassword(GetPassword());
            route.MinutesBetweenTry = 5;
            route.Save();

            return(route);
        }
Example #4
0
        public void TestAuthFailurePasswordInBounce()
        {
            Assert.AreEqual(0, _status.UndeliveredMessages.Length);

            // No valid recipients...
            Dictionary <string, int> deliveryResults = new Dictionary <string, int>();

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

            SMTPServerSimulator server = new SMTPServerSimulator(1, 250);

            server.AddRecipientResult(deliveryResults);
            server.SimulatedError = SimulatedErrorType.ForceAuthenticationFailure;
            server.StartListen();

            // Add a route so we can connect to localhost.
            hMailServer.Route route = AddRoutePointingAtLocalhost(5, 250, false);
            route.RelayerRequiresAuth = true;
            route.RelayerAuthUsername = "******";
            route.SetRelayerAuthPassword("MySecretPassword");

            // Send message to this route.
            SMTPClientSimulator smtp       = new SMTPClientSimulator();
            List <string>       recipients = new List <string>();

            recipients.Add("*****@*****.**");
            Assert.IsTrue(smtp.Send("*****@*****.**", recipients, "Test", "Test message"));

            // Wait for the client to disconnect.
            server.WaitForCompletion();

            Utilities.AssertRecipientsInDeliveryQueue(0);

            string messageText = POP3Simulator.AssertGetFirstMessageText(_account.Address, "test");

            Assert.IsFalse(messageText.Contains("MySecretPassword"));
            Assert.IsTrue(messageText.Contains("<Password removed>"));
        }