Example #1
0
        MailListener mailListener = new MailListener("localhost", 25); // Listens for incoming mails.

        // "var" keyword as well as INITIALIZING WON'T WORK IN CLASS DEFINITION.
        private void StartSmtp()
        {
            var options = new OptionsBuilder()
            .WithServerName("localhost")
            .WithPort(25, 587)
            .WithMessageStore(new ConsoleMessageStore())
            //.WithMailboxFilter(new MailboxFilter())
            //.WithUserAuthenticator(new UserAuthenticator())
            .Build();

            var smtpServer = new SmtpServer(options);
            smtpServer.StartAsync(CancellationToken.None);
            
            //await smtpServer.StartAsync(CancellationToken.None);*/


        }
Example #2
0
        static void Main(string[] args)
        {
            var cancellationTokenSource = new CancellationTokenSource();

            var certificate = CreateCertificate();

            ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateValidationFailureForTestingOnly;

            var options = new OptionsBuilder()
                .ServerName("SmtpServer SampleApp")
                .Port(9025)
                .Certificate(certificate)
                .MessageStore(new ConsoleMessageStore())
                .MailboxFilter(new ConsoleMailboxFilter())
                .Build();

            if (args == null || args.Length == 0)
            {
                var serverTask = RunServerAsync(options, cancellationTokenSource.Token);
                var clientTask1 = RunClientAsync("A", cancellationTokenSource.Token);
                var clientTask2 = RunClientAsync("B", cancellationTokenSource.Token);
                var clientTask3 = RunClientAsync("C", cancellationTokenSource.Token);

                Console.WriteLine("Press any key to continue");
                Console.ReadKey();

                cancellationTokenSource.Cancel();

                serverTask.WaitWithoutException();
                clientTask1.WaitWithoutException();
                clientTask2.WaitWithoutException();
                clientTask3.WaitWithoutException();

                return;
            }

            if (args[0] == "server")
            {
                var serverTask = RunServerAsync(options, cancellationTokenSource.Token);

                Console.WriteLine("Press any key to continue");
                Console.ReadKey();

                cancellationTokenSource.Cancel();

                serverTask.WaitWithoutException();

                return;
            }

            if (args[0] == "client")
            {
                var clientTask = RunClientAsync(args[1], cancellationTokenSource.Token);

                Console.WriteLine("Press any key to continue");
                Console.ReadKey();

                cancellationTokenSource.Cancel();

                clientTask.WaitWithoutException();
            }
        }