我有一些代码无法成功执行,我无法理解原因。
此功能:
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 john.holland@covenant.edu。由于某种原因,RCPT TO:命令遇到错误说:
"返回代码:500#5.5.1命令无法识别"
编辑:我确实通过远程登录手动尝试了
答案 0 :(得分:1)
您正在追加\r\n
两次 - 在send()
生成字符串时一次,在sendCommand()
调用中print()
一次。
第二个\r\n
会触发500 5.5.1 Unrecognized command.