protected void SendCommand(String Command) { var CommandBytes = Encoding.UTF8.GetBytes(Command + "\r\n"); TCPSocket.Poll(SelectMode.SelectWrite, CancellationToken.Value); Stream.Write(CommandBytes, 0, CommandBytes.Length); }
private SMTPExtendedResponse ReadSMTPResponse() { try { if (input == null || input.Length == 0) { input = new Byte[64 * 1024]; var nread = 0; TCPSocket.Poll(SelectMode.SelectRead, CancellationToken.Value); if ((nread = Stream.Read(input, 0, input.Length)) == 0) { throw new Exception("The SMTP server unexpectedly disconnected."); } Array.Resize(ref input, nread); } var aa = input.TakeWhile(b => b != ' ' && b != '-').ToArray().ToUTF8String(); var more = input[aa.Length] == '-'; var resp = input.Skip(aa.Length + 1). TakeWhile(b => b != '\r' && b != '\n'). ToArray(); var scode = SMTPStatusCode.SyntaxError; UInt16 _scode; if (UInt16.TryParse(aa, out _scode)) { scode = (SMTPStatusCode)_scode; } if (more) { input = input.Skip(aa.Length + 1 + resp.Length).SkipWhile(b => b == '\r' || b == '\n'). ToArray(); } else { input = null; } return(new SMTPExtendedResponse(scode, resp.ToUTF8String().Trim(), more)); } catch (Exception e) { return(new SMTPExtendedResponse(SMTPStatusCode.TransactionFailed, e.Message)); } }