subethasmtp服务器不从客户端打印消息

时间:2014-12-28 21:32:52

标签: java email smtp javamail smtpclient

当我运行客户端时,它应该向我的服务器发送一封电子邮件,然后我希望我的电子邮件服务器将电子邮件详细信息(从,从,端口,消息)打印到控制台。出于某种原因,在运行客户端后,服务器上没有任何明显的事情发生。

服务器

package example;

import org.subethamail.smtp.server.SMTPServer;

public class EmailServer {

    public static void main(String[] args) {
        MyMessageHandlerFactory myFactory = new MyMessageHandlerFactory();
        SMTPServer smtpServer = new SMTPServer(myFactory);
        smtpServer.setPort(25000);
        smtpServer.start();
    }
}

服务器输出

  

运行:[main] INFO org.subethamail.smtp.server.SMTPServer - SMTP服务器   *:25000起始[org.subethamail.smtp.server.ServerThread *:25000] INFO org.subethamail.smtp.server.ServerThread - SMTP服务器*:25000   开始

客户端

package example;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.subethamail.smtp.client.*;

public class EmailClient {

    public static void main(String[] args) {
        try {
            SMTPClient sc = new SMTPClient();
            sc.close();
            sc.connect("localhost", 25000);
            sc.sendReceive("test");
        } catch (IOException ex) {
            Logger.getLogger(EmailClient.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}

客户输出

  

run:BUILD SUCCESSFUL(总时间:0秒)

版本<{3}}

3.1.7

服务器需要我复制的 MyMessageHandlerFactory https://code.google.com/p/subethasmtp/downloads/list

1 个答案:

答案 0 :(得分:0)

好的,让我们检查源代码(总是一个好主意),看看会发生什么。

你发送&#34;测试&#34;通过

SMTPClient sc;
sc.sendReceive("test"); // which is actually sent to your SMTPServer as "test\r\n"

现在,考虑到这是一个新的SMTP会话(请参阅RFC5321了解您一直想知道但却不敢询问的事情)和&#34; 测试& #34;在会话中此时不是有效的命令VERB,您可能会看到sendReceive()返回的错误。

但是,因为你忽略了应该从

返回的SMTPClient.Response#75
Response resp=SMTPClient.sendReceive()

你错过了

  • resp.code(我确定是500 - Permanent Negative Completion reply / Syntax - 请参阅上面的RFC)和
  • resp.message描述了你的命令无法满足的原因

这两项都是从CommandHandler#93返回的。