Stop() 공개 메소드

public Stop ( ) : void
리턴 void
예제 #1
1
        public void TestMailDeliveryAsync()
        {
            SmtpServer server = new SmtpServer();
            SmtpClient client = new SmtpClient("localhost", server.EndPoint.Port);
            MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "hello", "howdydoo");

            Thread t = new Thread(server.Run);
            t.Start();
            Task task = client.SendMailAsync(msg);
            t.Join();

            server.Stop();

            Assert.Equal("<*****@*****.**>", server.MailFrom);
            Assert.Equal("<*****@*****.**>", server.MailTo);
            Assert.Equal("hello", server.Subject);
            Assert.Equal("howdydoo", server.Body);

            Assert.True(task.Wait(1000));
        }
예제 #2
0
        public async Task TestCredentialsCopyInAsyncContext()
        {
            SmtpServer  server       = new SmtpServer();
            SmtpClient  client       = new SmtpClient("localhost", server.EndPoint.Port);
            MailMessage msg          = new MailMessage("*****@*****.**", "*****@*****.**", "hello", "howdydoo");
            string      clientDomain = IPGlobalProperties.GetIPGlobalProperties().HostName.Trim().ToLower();

            CredentialCache cache = new CredentialCache();

            cache.Add("localhost", server.EndPoint.Port, "NTLM", CredentialCache.DefaultNetworkCredentials);

            client.Credentials = cache;

            try
            {
                Thread t = new Thread(server.Run);
                t.Start();
                await client.SendMailAsync(msg);

                t.Join();

                Assert.Equal("<*****@*****.**>", server.MailFrom);
                Assert.Equal("<*****@*****.**>", server.MailTo);
                Assert.Equal("hello", server.Subject);
                Assert.Equal("howdydoo", server.Body);
                Assert.Equal(clientDomain, server.ClientDomain);
            }
            finally
            {
                server.Stop();
            }
        }
예제 #3
0
        public async Task TestMailDeliveryAsync()
        {
            SmtpServer  server       = new SmtpServer();
            SmtpClient  client       = new SmtpClient("localhost", server.EndPoint.Port);
            MailMessage msg          = new MailMessage("*****@*****.**", "*****@*****.**", "hello", "howdydoo");
            string      clientDomain = IPGlobalProperties.GetIPGlobalProperties().HostName.Trim().ToLower();

            try
            {
                Thread t = new Thread(server.Run);
                t.Start();
                await client.SendMailAsync(msg);

                t.Join();

                Assert.Equal("<*****@*****.**>", server.MailFrom);
                Assert.Equal("<*****@*****.**>", server.MailTo);
                Assert.Equal("hello", server.Subject);
                Assert.Equal("howdydoo", server.Body);
                Assert.Equal(clientDomain, server.ClientDomain);
            }
            finally
            {
                server.Stop();
            }
        }
예제 #4
0
        public void TestMailDelivery()
        {
            SmtpServer server = new SmtpServer();
            SmtpClient client = new SmtpClient("localhost", server.EndPoint.Port);

            client.Credentials = new NetworkCredential("user", "password");
            MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "hello", "howdydoo");

            try
            {
                Thread t = new Thread(server.Run);
                t.Start();
                client.Send(msg);
                t.Join();

                Assert.Equal("<*****@*****.**>", server.MailFrom);
                Assert.Equal("<*****@*****.**>", server.MailTo);
                Assert.Equal("hello", server.Subject);
                Assert.Equal("howdydoo", server.Body);
            }
            finally
            {
                server.Stop();
            }
        }
예제 #5
0
        [InlineData(true, true, true)]  // Received subjectBase64. If subjectText is received, the test fails, and the results are inconsistent with those of synchronous methods.
        public void SendMail_DeliveryFormat_SubjectEncoded(bool useAsyncSend, bool useSevenBit, bool useSmtpUTF8)
        {
            // If the server support `SMTPUTF8` and use `SmtpDeliveryFormat.International`, the server should received this subject.
            const string subjectText = "Test \u6d4b\u8bd5 Contain \u5305\u542b UTF8";

            // If the server does not support `SMTPUTF8` or use `SmtpDeliveryFormat.SevenBit`, the server should received this subject.
            const string subjectBase64 = "=?utf-8?B?VGVzdCDmtYvor5UgQ29udGFpbiDljIXlkKsgVVRGOA==?=";

            SmtpServer server = new SmtpServer();

            // Setting up Server Support for `SMTPUTF8`.
            server.SupportSmtpUTF8 = useSmtpUTF8;

            SmtpClient client = new SmtpClient("localhost", server.EndPoint.Port);

            if (useSevenBit)
            {
                // Subject will be encoded by Base64.
                client.DeliveryFormat = SmtpDeliveryFormat.SevenBit;
            }
            else
            {
                // If the server supports `SMTPUTF8`, subject will not be encoded. Otherwise, subject will be encoded by Base64.
                client.DeliveryFormat = SmtpDeliveryFormat.International;
            }

            MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", subjectText, "hello \u9ad8\u575a\u679c");

            msg.HeadersEncoding = msg.BodyEncoding = msg.SubjectEncoding = System.Text.Encoding.UTF8;

            try
            {
                Thread t = new Thread(server.Run);
                t.Start();

                if (useAsyncSend)
                {
                    client.SendMailAsync(msg).Wait();
                }
                else
                {
                    client.Send(msg);
                }

                if (useSevenBit || !useSmtpUTF8)
                {
                    Assert.Equal(subjectBase64, server.Subject);
                }
                else
                {
                    Assert.Equal(subjectText, server.Subject);
                }
            }
            finally
            {
                server.Stop();
            }
        }
예제 #6
0
        public void TestMailDeliveryAsync()
        {
            SmtpServer  server = new SmtpServer();
            SmtpClient  client = new SmtpClient("localhost", server.EndPoint.Port);
            MailMessage msg    = new MailMessage("*****@*****.**", "*****@*****.**", "hello", "howdydoo");

            Thread t = new Thread(server.Run);

            t.Start();
            Task task = client.SendMailAsync(msg);

            t.Join();

            server.Stop();

            Assert.Equal("<*****@*****.**>", server.MailFrom);
            Assert.Equal("<*****@*****.**>", server.MailTo);
            Assert.Equal("hello", server.Subject);
            Assert.Equal("howdydoo", server.Body);

            Assert.True(task.Wait(1000));
        }
예제 #7
0
        public async Task TestMailDeliveryAsync()
        {
            SmtpServer  server = new SmtpServer();
            SmtpClient  client = new SmtpClient("localhost", server.EndPoint.Port);
            MailMessage msg    = new MailMessage("*****@*****.**", "*****@*****.**", "hello", "howdydoo");

            try
            {
                Thread t = new Thread(server.Run);
                t.Start();
                await client.SendMailAsync(msg);

                t.Join();

                Assert.Equal("<*****@*****.**>", server.MailFrom);
                Assert.Equal("<*****@*****.**>", server.MailTo);
                Assert.Equal("hello", server.Subject);
                Assert.Equal("howdydoo", server.Body);
            }
            finally
            {
                server.Stop();
            }
        }
예제 #8
0
        public void TestMailDelivery()
        {
            SmtpServer server = new SmtpServer();
            SmtpClient client = new SmtpClient("localhost", server.EndPoint.Port);
            client.Credentials = new NetworkCredential("user", "password");
            MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "hello", "howdydoo");

            Thread t = new Thread(server.Run);
            t.Start();
            client.Send(msg);
            t.Join();

            server.Stop();

            Assert.Equal("<*****@*****.**>", server.MailFrom);
            Assert.Equal("<*****@*****.**>", server.MailTo);
            Assert.Equal("hello", server.Subject);
            Assert.Equal("howdydoo", server.Body);
        }
예제 #9
0
        public async void TestCredentialsCopyInAsyncContext()
        {
            SmtpServer server = new SmtpServer();
            SmtpClient client = new SmtpClient("localhost", server.EndPoint.Port);
            MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "hello", "howdydoo");

            CredentialCache cache = new CredentialCache();
            cache.Add("localhost", server.EndPoint.Port, "NTLM", CredentialCache.DefaultNetworkCredentials);

            client.Credentials = cache;

            try
            {
                Thread t = new Thread(server.Run);
                t.Start();
                await client.SendMailAsync(msg);
                t.Join();

                Assert.Equal("<*****@*****.**>", server.MailFrom);
                Assert.Equal("<*****@*****.**>", server.MailTo);
                Assert.Equal("hello", server.Subject);
                Assert.Equal("howdydoo", server.Body);
            }
            finally
            {
                server.Stop();
            }
        }