我有一个应用程序监视Exchange Server邮箱的传入邮件。它适用于其他系统,但对于我们的一个客户,我们收到错误:-ERR Command is not valid in this state.
我认为它与代码本身无关,因为我们在尝试使用Telnet登录时会收到相同的错误消息。用户通过时出错。仅供参考,我在下面添加了我的登录代码。
try
{
tcpClient = new TcpClient(Host, Port);
}
catch (SocketException e) { ... }
String response = "";
try
{
streamReader = GetStreamReader(tcpClient);
response = streamReader.ReadLine();
if (response.StartsWith("+OK"))
{
response = SendReceive("USER ", UserName.Trim() + "@" + Domain.Trim());
if (response.StartsWith("+OK"))
response = SendReceive("PASS ", Password);
}
}
catch (Exception e) { ... }
SendReceive方法如下:
private String SendReceive(String command, String parameter)
{
String result = null;
try
{
String myCommand = command.ToUpper().Trim() + " " + parameter.Trim() + Environment.NewLine;
byte[] data = System.Text.Encoding.ASCII.GetBytes(myCommand.ToCharArray());
tcpClient.GetStream().Write(data, 0, data.Length);
result = streamReader.ReadLine();
}
catch { } // Not logged in...
return result;
}