Beispiel #1
0
 //[ExpectedException(typeof(Win32Exception), ExpectedMessage="DNS name does not exist")]
 public void TestQueryInvalidDomain()
 {
     Assert.Throws <Win32Exception>(() =>
     {
         const string domain = "thisdomaindoesnotexist123456.net";
         DnsQuery.QueryMx(domain);
     });
 }
Beispiel #2
0
        public void TestQueryMxSlashdot()
        {
            const string domain = "slashdot.org";

            Log.InfoFormat("Query domain '{0}'", domain);
            var mailExchangers = DnsQuery.QueryMx(domain);

            LogMxs(domain, mailExchangers);

            Assert.IsNotNull(mailExchangers);
            Assert.AreEqual(mailExchangers.Count(), 1);
        }
Beispiel #3
0
        public void TestQueryMxSlashdot()
        {
            const string domain = "slashdot.org";

            Log.Info("Query domain '{0}'", domain);
            var mailExchangers = DnsQuery.QueryMx(domain);

            LogMxs(domain, mailExchangers);

            mailExchangers.ShouldNotBeNull();
            mailExchangers.Count().ShouldEqual(1);
        }
Beispiel #4
0
        public void TestQueryMxGoogle()
        {
            const string domain = "google.com";

            Log.Info("Query domain '{0}'", domain);
            var mailExchangers = DnsQuery.QueryMx(domain);

            LogMxs(domain, mailExchangers);

            mailExchangers.ShouldNotBeNull();
            5.ShouldEqual(mailExchangers.Count());
        }
Beispiel #5
0
        public void TestQueryMxTrademe()
        {
            const string domain = "trademe.co.nz";

            Log.InfoFormat("Query domain '{0}'", domain);
            var mailExchangers = DnsQuery.QueryMx(domain);

            LogMxs(domain, mailExchangers);

            Assert.IsNotNull(mailExchangers);
            Assert.AreEqual(mailExchangers.Count(), 8);
        }
Beispiel #6
0
        public void TestQueryMxGoogle()
        {
            const string domain = "google.com";

            Log.InfoFormat("Query domain '{0}'", domain);
            var mailExchangers = DnsQuery.QueryMx(domain);

            LogMxs(domain, mailExchangers);

            Assert.IsNotNull(mailExchangers);
            Assert.AreEqual(5, mailExchangers.Count());
        }
Beispiel #7
0
        public void TestQueryMxTrademe()
        {
            const string domain = "trademe.co.nz";

            Log.Info("Query domain '{0}'", domain);
            var mailExchangers = DnsQuery.QueryMx(domain);

            LogMxs(domain, mailExchangers);

            mailExchangers.ShouldNotBeNull();
            mailExchangers.ShouldNotBeEmpty();
            mailExchangers.Count().ShouldBeGreaterThanOrEqualTo(3);
        }
Beispiel #8
0
        public void TestDoubleQueryMxTrademe()
        {
            const string domain = "trademe.co.nz";
            var          mailExchangersQuery1 = DnsQuery.QueryMx(domain);
            var          mailExchangersQuery2 = DnsQuery.QueryMx(domain);

            Log.Info("First");
            LogMxs(domain, mailExchangersQuery1);
            Log.Info("Second");
            LogMxs(domain, mailExchangersQuery2);

            Assert.IsNotNull(mailExchangersQuery1);
            Assert.IsNotNull(mailExchangersQuery2);
            Assert.AreEqual(mailExchangersQuery1.Count(), mailExchangersQuery2.Count);
        }
Beispiel #9
0
        public static string MakeDefaultTransport()
        {
            var env = Environment.GetEnvironmentVariable("LOG4NET_SMTP_CONFIG");

            if (!string.IsNullOrEmpty(env))
            {
                LogLog.Debug(typeof(SmtpClientFactory), string.Format("Using environment based configuration '{0}", env));
                return(env);
            }
            else
            {
                var domain = DnsUtils.GetDomainName();
                if (!string.IsNullOrEmpty(domain))
                {
                    var mxs      = DnsQuery.QueryMx(domain);
                    var mxRecord = mxs.OrderBy(mx => mx.Preference).FirstOrDefault();
                    if (mxRecord != null && !string.IsNullOrEmpty(mxRecord.Name))
                    {
                        return(string.Format("smtp://smtp.{0}", mxRecord.Name));
                    }
                    else
                    {
                        LogLog.Debug(
                            typeof(SmtpClientFactory),
                            string.Format(
                                "The domain '{0}' has no MX record, using localhost as the SMTP smart host", domain));
                        return("smtp://localhost");
                    }
                }
                else
                {
                    LogLog.Debug(
                        typeof(SmtpClientFactory),
                        "The machine has no domain name (primary DNS suffix), using localhost as the SMTP smart host");
                    return("smtp://localhost");
                }
            }
        }
        /// <summary>
        ///     Attempt to make a default SMTP transport URI. The URI is defaulted in the following
        ///     order:
        ///     <list type="bullet">
        ///         <item>From the environment variable 'NLOG_SMTP_CONFIG'</item>
        ///         <item>By querying if the host has a domain MX record</item>
        ///         <item>A local SMTP start host on port 25 with no authentication (e.g. IIS SMTP mailer)</item>
        ///     </list>
        /// </summary>
        public static string MakeDefaultTransport()
        {
            var env = Environment.GetEnvironmentVariable("NLOG_SMTP_CONFIG");

            if (!string.IsNullOrEmpty(env))
            {
                InternalLogger.Debug("Using environment based configuration '{0}", env);
                return(env);
            }
            else
            {
                var domain = DnsUtils.GetDomainName();
                if (!string.IsNullOrEmpty(domain))
                {
                    var mxs      = DnsQuery.QueryMx(domain);
                    var mxRecord = mxs
                                   .OrderBy(mx => mx.Preference)
                                   .FirstOrDefault();
                    if (!string.IsNullOrEmpty(mxRecord?.Name))
                    {
                        return($"smtp://{mxRecord.Name}");
                    }
                    else
                    {
                        InternalLogger.Debug(
                            "The domain '{0}' has no MX record, using localhost as the SMTP smart host", domain);
                        return("smtp://localhost");
                    }
                }
                else
                {
                    InternalLogger.Debug(
                        "The machine has no domain name (primary DNS suffix), using localhost as the SMTP smart host");
                    return("smtp://localhost");
                }
            }
        }
Beispiel #11
0
        public void TestQueryInvalidDomain()
        {
            const string domain = "thisdomaindoesnotexist123456.net";

            DnsQuery.QueryMx(domain);
        }