public void POP3ServerNOTSupportingStartTLS_StartTLSOptional()
        {
            var messages = new List<string>();

             string message = "From: [email protected]\r\n" +
                          "To: [email protected]\r\n" +
                          "Subject: Test\r\n" +
                          "\r\n" +
                          "Hello!";

             messages.Add(message);

             int port = TestSetup.GetNextFreePort();
             using (var pop3Server = new Pop3ServerSimulator(1, port, messages, eConnectionSecurity.eCSNone))
             {
            pop3Server.SetCertificate(SslSetup.GetCertificate());
            pop3Server.StartListen();

            LogHandler.DeleteCurrentDefaultLog();

            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
            FetchAccount fa = account.FetchAccounts.Add();

            fa.Enabled = true;
            fa.MinutesBetweenFetch = 10;
            fa.Name = "Test";
            fa.Username = "******";
            fa.Password = "******";
            fa.ConnectionSecurity = eConnectionSecurity.eCSSTARTTLSOptional;
            fa.ServerAddress = "localhost";
            fa.Port = port;
            fa.ProcessMIMERecipients = false;
            fa.Save();

            fa.DownloadNow();
            pop3Server.WaitForCompletion();

            Pop3ClientSimulator.AssertMessageCount("*****@*****.**", "test", 1);

            fa.Delete();
             }
        }
        public void POP3ServerNOTSupportingStartTLS_StartTLSRequired()
        {
            var messages = new List<string>();

             string message = "From: [email protected]\r\n" +
                          "To: [email protected]\r\n" +
                          "Subject: Test\r\n" +
                          "\r\n" +
                          "Hello!";

             messages.Add(message);

             int port = TestSetup.GetNextFreePort();
             using (var pop3Server = new Pop3ServerSimulator(1, port, messages, eConnectionSecurity.eCSNone))
             {
            pop3Server.SetCertificate(SslSetup.GetCertificate());
            pop3Server.StartListen();

            LogHandler.DeleteCurrentDefaultLog();

            Account account = SingletonProvider<TestSetup>.Instance.AddAccount(_domain, "*****@*****.**", "test");
            FetchAccount fa = account.FetchAccounts.Add();

            fa.Enabled = true;
            fa.MinutesBetweenFetch = 10;
            fa.Name = "Test";
            fa.Username = "******";
            fa.Password = "******";
            fa.ConnectionSecurity = eConnectionSecurity.eCSSTARTTLSRequired;
            fa.ServerAddress = "localhost";
            fa.Port = port;
            fa.ProcessMIMERecipients = false;
            fa.Save();

            fa.DownloadNow();

            string expectedMessage =
               string.Format(
                  "The download of messages from external account {0} failed. The external aAccount is configured to use STARTTLS connection security, but the POP3 server does not support it.", fa.Name);

            string contentSoFar = "";

            for (int i = 0; i <= 10; i++)
            {
               if (i == 5)
                  Assert.Fail("No connection: " + contentSoFar);

               contentSoFar = LogHandler.ReadCurrentDefaultLog();
               if (contentSoFar.Contains(expectedMessage))
                  break;

               Thread.Sleep(1000);
            }

            pop3Server.WaitForCompletion();

            fa.Delete();
             }
        }