Пример #1
0
        public void Data(string mail)
        {
            SetupCommandTimeout();

            var reply = SendCommand(SmtpCommands.DATA);

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

            if (mail.Contains(_endOfMailData))
            {
                throw new Exception("Mail data cannot contain terminator");
            }

            mail += _endOfMailData;
            byte[] buffer = Encoding.UTF8.GetBytes(mail);
            _stream.Write(buffer, 0, buffer.Length);

            reply = _reader.ReadServerReply();
            if (reply.Code != SmtpReplyCode.OK)
            {
                throw new Exception();
            }
        }
Пример #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;
        }