示例#1
0
        public static SMTPTestResult TestMailServer(string MailServer, int Port, bool TryOtherPorts)
        {
            SMTPTestResult result = new SMTPTestResult();

            result.Server = MailServer;

            if (AttemptMailServer(MailServer, Port, false, out result.Response))
            {
                //First try the requested port, without SSL.
                result.Found               = true;
                result.UsedSSL             = false;
                result.OriginalPortSuccess = true;
                result.FinalPort           = Port;
                return(result);
            }
            else if (AttemptMailServer(MailServer, Port, true, out result.Response))
            {
                //Try the requested port, with SSL.
                result.Found               = true;
                result.UsedSSL             = true;
                result.OriginalPortSuccess = true;
                result.FinalPort           = Port;
                return(result);
            }
            else if (TryOtherPorts && Port != 465 && AttemptMailServer(MailServer, 465, true, out result.Response))
            {
                //Try port 465 with SSL
                result.Found               = true;
                result.UsedSSL             = true;
                result.OriginalPortSuccess = false;
                result.FinalPort           = 465;
                return(result);
            }
            else if (TryOtherPorts && Port != 25 && AttemptMailServer(MailServer, 25, false, out result.Response))
            {
                //Try port 25, without SSL.
                result.Found               = true;
                result.UsedSSL             = false;
                result.OriginalPortSuccess = false;
                result.FinalPort           = 25;
                return(result);
            }
            else if (TryOtherPorts && Port != 25 && AttemptMailServer(MailServer, 25, true, out result.Response))
            {
                //Try port 25, with SSL.
                result.Found               = true;
                result.UsedSSL             = true;
                result.OriginalPortSuccess = false;
                result.FinalPort           = 25;
                return(result);
            }
            else if (TryOtherPorts && Port != 587 && AttemptMailServer(MailServer, 587, false, out result.Response))
            {
                //Try port 587, without SSL.
                result.Found               = true;
                result.UsedSSL             = false;
                result.OriginalPortSuccess = false;
                result.FinalPort           = 587;
                return(result);
            }
            else if (TryOtherPorts && Port != 587 && AttemptMailServer(MailServer, 587, true, out result.Response))
            {
                //Try port 587, with SSL.
                result.Found               = true;
                result.UsedSSL             = true;
                result.OriginalPortSuccess = false;
                result.FinalPort           = 587;
                return(result);
            }
            else
            {
                result.Found = false;
                result.OriginalPortSuccess = false;
                result.FinalPort           = Port;
                return(result);
            }
        }
示例#2
0
        public static SMTPTestResult TestMailServer(string MailServer, int Port, bool TryOtherPorts)
        {
            SMTPTestResult result = new SMTPTestResult();
            result.Server = MailServer;

            if (AttemptMailServer(MailServer, Port, false, out result.Response))
            {
                //First try the requested port, without SSL.
                result.Found = true;
                result.UsedSSL = false;
                result.OriginalPortSuccess = true;
                result.FinalPort = Port;
                return result;
            }
            else if (AttemptMailServer(MailServer, Port, true, out result.Response))
            {
                //Try the requested port, with SSL.
                result.Found = true;
                result.UsedSSL = true;
                result.OriginalPortSuccess = true;
                result.FinalPort = Port;
                return result;
            }
            else if (TryOtherPorts && Port != 465 && AttemptMailServer(MailServer, 465, true, out result.Response))
            {
                //Try port 465 with SSL
                result.Found = true;
                result.UsedSSL = true;
                result.OriginalPortSuccess = false;
                result.FinalPort = 465;
                return result;
            }
            else if (TryOtherPorts && Port != 25 && AttemptMailServer(MailServer, 25, false, out result.Response))
            {
                //Try port 25, without SSL.
                result.Found = true;
                result.UsedSSL = false;
                result.OriginalPortSuccess = false;
                result.FinalPort = 25;
                return result;
            }
            else if (TryOtherPorts && Port != 25 && AttemptMailServer(MailServer, 25, true, out result.Response))
            {
                //Try port 25, with SSL.
                result.Found = true;
                result.UsedSSL = true;
                result.OriginalPortSuccess = false;
                result.FinalPort = 25;
                return result;
            }
            else if (TryOtherPorts && Port != 587 && AttemptMailServer(MailServer, 587, false, out result.Response))
            {
                //Try port 587, without SSL.
                result.Found = true;
                result.UsedSSL = false;
                result.OriginalPortSuccess = false;
                result.FinalPort = 587;
                return result;
            }
            else if (TryOtherPorts && Port != 587 && AttemptMailServer(MailServer, 587, true, out result.Response))
            {
                //Try port 587, with SSL.
                result.Found = true;
                result.UsedSSL = true;
                result.OriginalPortSuccess = false;
                result.FinalPort = 587;
                return result;
            }
            else
            {
                result.Found = false;
                result.OriginalPortSuccess = false;
                result.FinalPort = Port;
                return result;
            }
        }