public void TestMailDelivery()
        {
            using var server        = new LoopbackSmtpServer();
            using SmtpClient client = server.CreateClient();
            client.Credentials      = new NetworkCredential("Foo", "Bar");
            MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "hello", "howdydoo");

            client.Send(msg);

            Assert.Equal("<*****@*****.**>", server.MailFrom);
            Assert.Equal("<*****@*****.**>", server.MailTo);
            Assert.Equal("hello", server.Message.Subject);
            Assert.Equal("howdydoo", server.Message.Body);
            Assert.Equal(GetClientDomain(), server.ClientDomain);
            Assert.Equal("Foo", server.Username);
            Assert.Equal("Bar", server.Password);
            Assert.Equal("LOGIN", server.AuthMethodUsed, StringComparer.OrdinalIgnoreCase);
        }
Beispiel #2
0
        public async Task TestCredentialsCopyInAsyncContext()
        {
            using var server        = new LoopbackSmtpServer();
            using SmtpClient client = server.CreateClient();
            MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", "hello", "howdydoo");

            CredentialCache cache = new CredentialCache();

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

            client.Credentials = cache;

            // The mock server doesn't actually understand NTLM, but still advertises support for it
            server.AdvertiseNtlmAuthSupport = true;
            await Assert.ThrowsAsync <SmtpException>(async() => await client.SendMailAsync(msg));

            Assert.Equal("NTLM", server.AuthMethodUsed, StringComparer.OrdinalIgnoreCase);
        }