Beispiel #1
0
        public void StartTls(string host)
        {
            SetupCommandTimeout();

            if (!SupportedCommands.Contains(SmtpCommands.STARTTLS))
            {
                throw new Exception("Not supported");
            }

            var reply = SendCommand(SmtpCommands.STARTTLS);

            if (reply.Code != SmtpReplyCode.ServiceReady)
            {
                throw new Exception();
            }

            var tls = _tlsProvider.AuthenticateAsClient(_stream, host);

            _stream = tls;
            _reader = new SmtpControlStreamReader(tls);
        }
Beispiel #2
0
        public void Connect(string host, int port)
        {
            if (Proxy != null)
            {
                Proxy.ConnectTimeout = ConnectTimeout;
                Proxy.ReadTimeout    = ReadTimeout;
                Proxy.WriteTimeout   = WriteTimeout;
                _tcpClient           = Proxy.CreateConnection(host, port);
            }
            else
            {
                _tcpClient = new TcpClient(AddressFamily.InterNetwork);
                _tcpClient.Connect(host, port);//
            }

            _stream = _tcpClient.GetStream();

            if (ReadTimeout >= 0)
            {
                _tcpClient.ReceiveTimeout = ReadTimeout;
            }
            if (WriteTimeout >= 0)
            {
                _tcpClient.SendTimeout = WriteTimeout;
            }

            _reader = new SmtpControlStreamReader(_stream);

            SetupCommandTimeout();

            var greetingReply = _reader.ReadServerReply();

            if (greetingReply.Code != SmtpReplyCode.ServiceReady)
            {
                throw new Exception();
            }

            Greeting = greetingReply.Message;
        }