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

            var reply = SendCommand(SmtpCommands.Data);

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

            if (mail.Contains(EndOfMailData))
            {
                throw new SmtpException("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 SmtpException();
            }
        }
Пример #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);//создание подключения по схеме адресации IP-адрес версии 4.
                _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 SmtpException();
            }

            Greeting = greetingReply.Message;
        }