1

我有一些代码无法成功执行,我不明白为什么。

这个功能:

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 命令无法识别”

编辑:我确实通过远程登录手动尝试了它们

4

1 回答 1

1

您追加\r\n了两次 - 一次是send()在构建字符串时,一次是sendCommand()print()调用中。

第二个\r\n触发500 5.5.1 Unrecognized command.

于 2013-02-03T03:09:33.997 回答