我有一些代码无法成功执行,我不明白为什么。
这个功能:
public void send(Envelope envelope) throws IOException
{
String CRLF = "\r\n";
sendCommand("MAIL FROM:"+ envelope.Sender + CRLF, 250);
//error occuring here. "Return Code:500 #5.5.1 command not recognized"
sendCommand("RCPT TO:" + envelope.Recipient + CRLF, 250);
sendCommand("DATA", 354);
toServer.print(envelope.Message.Headers + CRLF);
toServer.print(envelope.Message.Body + CRLF);
toServer.print("." +CRLF);
}
上面的代码调用了这个函数:
private void sendCommand(String command, int rc) throws IOException
{
/* Write command to server */
toServer.print(command + CRLF);
/*read reply from server. */
String line = fromServer.readLine();
System.err.println("Request: " + command);
System.err.println("Return Code:" + line);
/*
* Check that the server's reply code is the same as the parameter rc.
* If not, throw an IOException.
*/
if (!line.substring(0,3).equals(rc+""))
{
throw new IOException();
}
}
信息是这样传输的:
Socket connection = new Socket(envelope.DestAddr, SMTP_PORT);
fromServer = new BufferedReader(new InputStreamReader(connection.getInputStream()));
toServer = new PrintStream(connection.getOutputStream());
我使用相同的 From 和 To。由于某种原因,RCPT TO: 命令遇到错误:
“返回码:500 #5.5.1 命令无法识别”
编辑:我确实通过远程登录手动尝试了它们