Esempio n. 1
0
        /// <summary>
        /// Validates syntax and existence of the given address.
        /// </summary>
        /// <param name="address">The address to be validated.</param>
        /// <param name="dnsServers">Name Servers to be used for MX records search.</param>
        /// <returns>True if the address is valid, otherwise false.</returns>
        public static bool Validate(string address, ServerCollection dnsServers)
        {
            if (!ActiveUp.Net.Mail.Validator.ValidateSyntax(address))
            {
                return(false);
            }
            else
            {
                string domain = address.Split('@')[1];
                bool   result;
                ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
                smtp.SendTimeout    = 15;
                smtp.ReceiveTimeout = 15;

                MxRecordCollection mxRecords = new MxRecordCollection();
                try
                {
#if !PocketPC
                    mxRecords = ActiveUp.Net.Mail.Validator.GetMxRecords(domain, dnsServers);
#else
                    mxRecords = ActiveUp.Net.Mail.Validator.GetMxRecords(domain);
#endif
                }
                catch
                {
                    new System.Exception("Can't connect to DNS server.");
                }
                smtp.Connect(mxRecords.GetPrefered().Exchange);
                try
                {
                    smtp.Ehlo(System.Net.Dns.GetHostName());
                }
                catch
                {
                    smtp.Helo(System.Net.Dns.GetHostName());
                }
                if (smtp.Verify(address))
                {
                    result = true;
                }
                else
                {
                    try
                    {
                        //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                        //smtp.MailFrom("*****@*****.**");
                        smtp.MailFrom(string.Format("postmaster@{0}", domain));
                        smtp.RcptTo(address);
                        result = true;
                    }
                    catch
                    {
                        result = false;
                    }
                }
                smtp.Disconnect();
                return(result);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Validates syntax and existence of the given address and returns valid addresses.
        /// </summary>
        /// <param name="addresses">The collection to be filtered.</param>
        /// <param name="dnsServers">Name Servers to be used for MX records search.</param>
        /// <returns>A collection containing the valid addresses.</returns>
        public static AddressCollection Filter(AddressCollection addresses, ServerCollection dnsServers)
        {
            ActiveUp.Net.Mail.AddressCollection valids = new ActiveUp.Net.Mail.AddressCollection();
            ActiveUp.Net.Mail.AddressCollection valids1 = new ActiveUp.Net.Mail.AddressCollection();
            System.Collections.Specialized.HybridDictionary ads = new System.Collections.Specialized.HybridDictionary();
            for (int i = 0; i < addresses.Count; i++)
                if (ActiveUp.Net.Mail.Validator.ValidateSyntax(addresses[i].Email)) valids.Add(addresses[i]);
#if !PocketPC
            System.Array domains = System.Array.CreateInstance(typeof(string), new int[] { valids.Count }, new int[] { 0 });
            System.Array adds = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address), new int[] { valids.Count }, new int[] { 0 });
#else
            System.Array domains = System.Array.CreateInstance(typeof(string), new int[] { valids.Count });
            System.Array adds = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address), new int[] { valids.Count });
#endif
            for (int i = 0; i < valids.Count; i++)
            {
                domains.SetValue(valids[i].Email.Split('@')[1], i);
                adds.SetValue(valids[i], i);
            }
            System.Array.Sort(domains, adds, null);
            string currentDomain = "";
            string address = "";
            ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
            bool isConnected = false;
            for (int i = 0; i < adds.Length; i++)
            {
                address = ((ActiveUp.Net.Mail.Address)adds.GetValue(i)).Email;
                if (((string)domains.GetValue(i)) == currentDomain)
                {
                    if (!smtp.Verify(address))
                    {
                        try
                        {
                            //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                            //smtp.MailFrom("postmaster@"+currentDomain);
                            smtp.RcptTo(address);
                            valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                        }
                        catch
                        {

                        }
                    }
                    else valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                }
                else
                {
                    currentDomain = (string)domains.GetValue(i);
                    try
                    {
                        if (isConnected == true)
                        {
                            isConnected = false;
                            smtp.Disconnect();
                            smtp = new ActiveUp.Net.Mail.SmtpClient();
                        }

                        smtp.Connect(ActiveUp.Net.Mail.Validator.GetMxRecords(currentDomain, dnsServers).GetPrefered().Exchange);
                        isConnected = true;
                        try
                        {
                            smtp.Ehlo(System.Net.Dns.GetHostName());
                        }
                        catch
                        {
                            smtp.Helo(System.Net.Dns.GetHostName());
                        }
                        if (!smtp.Verify(address))
                        {
                            try
                            {
                                //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                                //smtp.MailFrom("*****@*****.**");
                                smtp.MailFrom("postmaster@" + currentDomain);
                                smtp.RcptTo(address);
                                valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                            }
                            catch
                            {

                            }
                        }
                        else valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                    }
                    catch
                    {

                    }
                }
            }
            if (isConnected == true)
                smtp.Disconnect();
            return valids1;
        }
Esempio n. 3
0
        /// <summary>
        /// Validates syntax and existence of the given address.
        /// </summary>
        /// <param name="address">The address to be validated.</param>
        /// <returns>True if the address is valid, otherwise false.</returns>
        public static bool Validate(string address)
        {
            if (!ActiveUp.Net.Mail.Validator.ValidateSyntax(address)) return false;
            else
            {
                try
                {
                    string domain = address.Split('@')[1];
                    bool result;
                    ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
                    smtp.SendTimeout = 0;
                    smtp.ReceiveTimeout = 0;
                    MxRecordCollection mxRecords = new MxRecordCollection();
                    try
                    {
                        mxRecords = ActiveUp.Net.Mail.Validator.GetMxRecords(domain);
                    }
                    catch
                    {
                        new System.Exception("Can't connect to DNS server.");
                    }
                    //Console.WriteLine(mxRecords.GetPrefered().Exchange);
                    if (mxRecords.Count > 0) smtp.Connect(mxRecords.GetPrefered().Exchange);
                    else return false;
                    try
                    {
                        smtp.Ehlo(System.Net.Dns.GetHostName());
                    }
                    catch
                    {
                        smtp.Helo(System.Net.Dns.GetHostName());
                    }
                    if (smtp.Verify(address)) result = true;
                    else
                    {
                        try
                        {
                            //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                            //smtp.MailFrom("*****@*****.**");
                            smtp.MailFrom("postmaster@" + domain);
                            smtp.RcptTo(address);
                            result = true;
                        }
                        catch (Exception ex)
                        {
                            System.Console.WriteLine(ex.ToString());
#if !PocketPC
                            System.Web.HttpContext.Current.Trace.Write("ActiveMail", ex.ToString());
#endif
                            result = false;
                        }
                    }
                    smtp.Disconnect();
                    return result;
                }
                catch
                {
                    return false;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Validates syntax and existence of the given address.
        /// </summary>
        /// <param name="address">The address to be validated.</param>
        /// <param name="dnsServers">Name Servers to be used for MX records search.</param>
        /// <returns>True if the address is valid, otherwise false.</returns>
        public static bool Validate(string address, ServerCollection dnsServers)
        {
            if (!ActiveUp.Net.Mail.Validator.ValidateSyntax(address)) return false;
            else
            {
                string domain = address.Split('@')[1];
                bool result;
                ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
                smtp.SendTimeout = 15;
                smtp.ReceiveTimeout = 15;

                MxRecordCollection mxRecords = new MxRecordCollection();
                try
                {
#if !PocketPC
                    mxRecords = ActiveUp.Net.Mail.Validator.GetMxRecords(domain, dnsServers);
#else
                    mxRecords = ActiveUp.Net.Mail.Validator.GetMxRecords(domain);
#endif
                }
                catch
                {
                    new System.Exception("Can't connect to DNS server.");
                }
                smtp.Connect(mxRecords.GetPrefered().Exchange);
                try
                {
                    smtp.Ehlo(System.Net.Dns.GetHostName());
                }
                catch
                {
                    smtp.Helo(System.Net.Dns.GetHostName());
                }
                if (smtp.Verify(address)) result = true;
                else
                {
                    try
                    {
                        //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                        //smtp.MailFrom("*****@*****.**");
                        smtp.MailFrom("postmaster@" + domain);
                        smtp.RcptTo(address);
                        result = true;
                    }
                    catch
                    {
                        result = false;
                    }
                }
                smtp.Disconnect();
                return result;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Validates syntax and existence of the given address and returns valid addresses.
        /// </summary>
        /// <param name="addresses">The collection to be filtered.</param>
        /// <param name="dnsServers">Name Servers to be used for MX records search.</param>
        /// <returns>A collection containing the valid addresses.</returns>
        public static AddressCollection Filter(AddressCollection addresses, ServerCollection dnsServers)
        {
            ActiveUp.Net.Mail.AddressCollection             valids  = new ActiveUp.Net.Mail.AddressCollection();
            ActiveUp.Net.Mail.AddressCollection             valids1 = new ActiveUp.Net.Mail.AddressCollection();
            System.Collections.Specialized.HybridDictionary ads     = new System.Collections.Specialized.HybridDictionary();
            for (int i = 0; i < addresses.Count; i++)
            {
                if (ActiveUp.Net.Mail.Validator.ValidateSyntax(addresses[i].Email))
                {
                    valids.Add(addresses[i]);
                }
            }
#if !PocketPC
            System.Array domains = System.Array.CreateInstance(typeof(string), new int[] { valids.Count }, new int[] { 0 });
            System.Array adds    = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address), new int[] { valids.Count }, new int[] { 0 });
#else
            System.Array domains = System.Array.CreateInstance(typeof(string), new int[] { valids.Count });
            System.Array adds    = System.Array.CreateInstance(typeof(ActiveUp.Net.Mail.Address), new int[] { valids.Count });
#endif
            for (int i = 0; i < valids.Count; i++)
            {
                domains.SetValue(valids[i].Email.Split('@')[1], i);
                adds.SetValue(valids[i], i);
            }
            System.Array.Sort(domains, adds, null);
            string currentDomain = "";
            string address       = "";
            ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
            bool isConnected = false;
            for (int i = 0; i < adds.Length; i++)
            {
                address = ((ActiveUp.Net.Mail.Address)adds.GetValue(i)).Email;
                if (((string)domains.GetValue(i)) == currentDomain)
                {
                    if (!smtp.Verify(address))
                    {
                        try
                        {
                            //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                            //smtp.MailFrom("postmaster@"+currentDomain);
                            smtp.RcptTo(address);
                            valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                    }
                }
                else
                {
                    currentDomain = (string)domains.GetValue(i);
                    try
                    {
                        if (isConnected == true)
                        {
                            isConnected = false;
                            smtp.Disconnect();
                            smtp = new ActiveUp.Net.Mail.SmtpClient();
                        }

                        smtp.Connect(ActiveUp.Net.Mail.Validator.GetMxRecords(currentDomain, dnsServers).GetPrefered().Exchange);
                        isConnected = true;
                        try
                        {
                            smtp.Ehlo(System.Net.Dns.GetHostName());
                        }
                        catch
                        {
                            smtp.Helo(System.Net.Dns.GetHostName());
                        }
                        if (!smtp.Verify(address))
                        {
                            try
                            {
                                //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                                //smtp.MailFrom("*****@*****.**");
                                smtp.MailFrom(string.Format("postmaster@{0}", currentDomain));
                                smtp.RcptTo(address);
                                valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            valids1.Add((ActiveUp.Net.Mail.Address)adds.GetValue(i));
                        }
                    }
                    catch
                    {
                    }
                }
            }
            if (isConnected == true)
            {
                smtp.Disconnect();
            }
            return(valids1);
        }
Esempio n. 6
0
        /// <summary>
        /// Validates syntax and existence of the given address.
        /// </summary>
        /// <param name="address">The address to be validated.</param>
        /// <returns>True if the address is valid, otherwise false.</returns>
        public static bool Validate(string address)
        {
            if (!ActiveUp.Net.Mail.Validator.ValidateSyntax(address))
            {
                return(false);
            }
            else
            {
                try
                {
                    string domain = address.Split('@')[1];
                    bool   result;
                    ActiveUp.Net.Mail.SmtpClient smtp = new ActiveUp.Net.Mail.SmtpClient();
                    smtp.SendTimeout    = 0;
                    smtp.ReceiveTimeout = 0;
                    MxRecordCollection mxRecords = new MxRecordCollection();
                    try
                    {
                        mxRecords = ActiveUp.Net.Mail.Validator.GetMxRecords(domain);
                    }
                    catch
                    {
                        new System.Exception("Can't connect to DNS server.");
                    }
                    //Console.WriteLine(mxRecords.GetPrefered().Exchange);
                    if (mxRecords.Count > 0)
                    {
                        smtp.Connect(mxRecords.GetPrefered().Exchange);
                    }
                    else
                    {
                        return(false);
                    }
                    try
                    {
                        smtp.Ehlo(System.Net.Dns.GetHostName());
                    }
                    catch
                    {
                        smtp.Helo(System.Net.Dns.GetHostName());
                    }
                    if (smtp.Verify(address))
                    {
                        result = true;
                    }
                    else
                    {
                        try
                        {
                            //smtp.MailFrom("postmaster@"+System.Net.Dns.GetHostName());
                            //smtp.MailFrom("*****@*****.**");
                            smtp.MailFrom(string.Format("postmaster@{0}", domain));
                            smtp.RcptTo(address);
                            result = true;
                        }
                        catch (Exception ex)
                        {
                            System.Console.WriteLine(ex.ToString());
#if !PocketPC
                            System.Web.HttpContext.Current.Trace.Write("ActiveMail", ex.ToString());
#endif
                            result = false;
                        }
                    }
                    smtp.Disconnect();
                    return(result);
                }
                catch
                {
                    return(false);
                }
            }
        }