예제 #1
0
        public bool Disconnect()
        {
            try
            {
                if (_streamWriter != null && _streamReader != null)
                {
                    if (this.IsConnected)
                    {
                        _streamWriter.WriteLine("QUIT");
                        _streamReader.ReadLine();
                    }
                }

                return true;
            }
            catch
            {
                //eat it.
                return false;
            }
            finally
            {
                if (_streamWriter != null && _streamReader != null)
                {
                    _streamWriter.Dispose();
                    _streamWriter = null;

                    _streamReader.Dispose();
                    _streamReader = null;
                }

                if (_networkStream != null)
                {
                    _networkStream.Dispose();
                    _networkStream = null;
                }

                if (_tcpClient != null)
                {
                    _tcpClient.Close();
                    _tcpClient = null;
                }
            }
        }
예제 #2
0
        public bool Connect()
        {
            this.ErrorMessage = string.Empty;

            for (int i = 0; i <= 4; i++)
            {

                TCPSocket.Connect(SMTPServer, Port);

                if (TCPSocket.Connected)
                {
                    //_networkStream = new NetworkStream(TCPSocket.GetStream());
                    _bufferedStream = new BufferedStream(TCPSocket.GetStream());
                    //_bufferedStream.ReadTimeout = ReadTimeout;
                    //_bufferedStream.WriteTimeout = WriteTimeout;

                    //_networkStream.ReadTimeout = ReadTimeout;
                    //_networkStream.WriteTimeout = WriteTimeout;

                    if (WriteToLog)
                        _smtpLogList = new List<string>();
                    _streamWriter = new SMTPWriter(_bufferedStream, _smtpLogList);
                    _streamWriter.AutoFlush = true;
                    _streamReader = new SMTPReader(_bufferedStream, _smtpLogList);

                    _streamReader.ReadLine(SMTP_SERVICE_READY_RESPONSE);
                    _streamWriter.WriteLine(string.Concat("HELO ", HELODomain));
                    _streamReader.ReadLine(SMTP_ACTION_COMPLETED_RESPONSE);

                    return true;
                }
            }

            return false;
        }