示例#1
0
        /// <summary>
        /// Write a string to the current connection.
        /// </summary>
        /// <param name="message"></param>
        private void Write(string message)
        {
            try
            {
                //log.Debug(message);
                _smtpserver.OnLogWriteSmtp(this, message);
                if (_captureConversation)
                {
                    _smtpserver.AppendConversation(SmtpProxy.CLIENT_LOG_PROMPT + message);
                }

                System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding();
                byte[] WriteBuffer           = new byte[1024];
                WriteBuffer = en.GetBytes(message);

                NetworkStream stream = GetStream();
                if (!stream.CanWrite)
                {
                    throw new MailException("Stream could not be opened for writing.");
                }
                stream.Write(WriteBuffer, 0, WriteBuffer.Length);
            }
            catch (Exception ex)
            {
                //LogError(ex.Message);
                throw new MailException("Error while sending data to the server: " + ex.Message, ex);
            }
        }