예제 #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 (!ValidateSyntax(address))
            {
                return(false);
            }
            else
            {
                string     domain = address.Split('@')[1];
                bool       result;
                SmtpClient smtp = new SmtpClient();
                smtp.SendTimeout    = 15;
                smtp.ReceiveTimeout = 15;

                MxRecordCollection mxRecords = new MxRecordCollection();
                try
                {
#if !PocketPC
                    mxRecords = GetMxRecords(domain, dnsServers);
#else
                    mxRecords = ActiveUp.Net.Mail.Validator.GetMxRecords(domain);
#endif
                }
                catch
                {
                    new 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);
            }
        }
예제 #2
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 (!ValidateSyntax(address))
            {
                return(false);
            }
            else
            {
                try
                {
                    string     domain = address.Split('@')[1];
                    bool       result;
                    SmtpClient smtp = new SmtpClient();
                    smtp.SendTimeout    = 0;
                    smtp.ReceiveTimeout = 0;
                    MxRecordCollection mxRecords = new MxRecordCollection();
                    try
                    {
                        mxRecords = GetMxRecords(domain);
                    }
                    catch
                    {
                        new 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)
                        {
#if (DEBUG)
                            Console.WriteLine(ex.ToString());
#endif
#if !PocketPC
                            HttpContext.Current.Trace.Write("ActiveMail", ex.ToString());
#endif
                            result = false;
                        }
                    }
                    smtp.Disconnect();
                    return(result);
                }
                catch
                {
                    return(false);
                }
            }
        }
예제 #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;
                }
            }
        }
예제 #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;
            }
        }