java - RCPT 至 : <rcpt@host> SMTP syntax

标签 java smtp

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

这个函数:

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: 命令遇到错误:

"Return Code:500 #5.5.1 command not recognized"

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

最佳答案

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

第二个\r\n触发500 5.5.1 Unrecognized命令。

关于java - RCPT 至 : <rcpt@host> SMTP syntax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14668479/

相关文章:

java - 如何在 jackson 序列化中自定义日期,@JsonSerialize不起作用

java - Eclipse/Flash Builder 文件搜索的正则表达式是否有评论?

c# - C# : The type or namespace 'SmptMailMessage' could not be found 错误

c++ - 连接到smtp服务器windows C++

objective-c - 通过套接字与 ESMTP 协商 TLS

ruby-on-rails - 使用 Amazon SES 对 Rails 应用程序进行 DKIM 签名

smtp - 使用纯文本、HTML 和 SMTP 附件的电子邮件的正确电子邮件格式?

java - QR 码显示为空白

java - 密码管理

Java SSHJ - 添加到 validator 中的known_hosts文件