2014-12-28 107 views
0

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

服务器

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(); 
    } 
} 

服务器输出

运行:[主要] INFO org.subethamail.smtp.server.SMTPServer - SMTP服务器 *:25000开始[有机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); 
     } 

    } 

} 

客户端输出

运行:BUILD SUCCESSFUL(总时间:0秒)

版是从https://code.google.com/p/subethasmtp/downloads/list3.1.7

服务器需要MyMessageHandlerFactory这是我从复制:https://code.google.com/p/subethasmtp/wiki/SimpleExample

回答

0

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

您通过

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

发送“测试”现在,考虑到这是一个新的SMTP会话(见RFC5321你一直想知道,但不敢问这些事情的一切)和“测试“在对话中此时不是有效的命令VERB,您将会看到由sendReceive()返回的错误。

但是因为你忽略了SMTPClient.Response#75从什么应该被

Response resp=SMTPClient.sendReceive() 

回到你就错过了两

  • resp.code(我敢肯定是500 - Permanent Negative Completion reply/Syntax - 参见RFC以上)和
  • resp.message描述你的命令不能完成的原因

这两者都从CommandHandler#93返回。

+0

哦,关于你的'IOException' try/catch,事务不会失败。相反,如果您选择关注它,它会尽职尽责地回报您的问题。 :-) –

+0

所以,我是这个图书馆的全新人物,从未碰过它。为了让我的服务器打印出客户端的电子邮件,你可以告诉我需要做哪些基本的代码级别更改? – ThreaT

+0

只需跟进,有没有机会看看我以前的评论? – ThreaT

相关问题