When I run the client it's supposed to send an email to my server and then I want my email server to print out the email details (to, from, port, message) to console. For some reason after running the client, nothing apparent happens on the server.
当我运行客户端时,它应该发送一封电子邮件到我的服务器,然后我希望我的电子邮件服务器打印出电子邮件详细信息(从,从,端口,消息)到控制台。出于某种原因,在运行客户端后,服务器上没有任何明显的事情发生
server
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();
}
}
server output
run: [main] INFO org.subethamail.smtp.server.SMTPServer - SMTP server *:25000 starting [org.subethamail.smtp.server.ServerThread *:25000] INFO org.subethamail.smtp.server.ServerThread - SMTP server *:25000 started
run:[main] INFO org.subethamail.smtp.server.SMTPServer - SMTP server *:25000 starting [org.subethamail.smtp.server.ServerThread *:25000] INFO org.subethamail.smtp.server.ServerThread - SMTP server * :25000开始了
client
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);
}
}
}
client output
run: BUILD SUCCESSFUL (total time: 0 seconds)
run:BUILD SUCCESSFUL(总时间:0秒)
Version is 3.1.7 from https://code.google.com/p/subethasmtp/downloads/list
版本为3.1.7,来自https://code.google.com/p/subethasmtp/downloads/list
The server requires MyMessageHandlerFactory which I copied from: https://code.google.com/p/subethasmtp/wiki/SimpleExample
服务器需要我复制的MyMessageHandlerFactory:https://code.google.com/p/subethasmtp/wiki/SimpleExample
1 个解决方案
#1
0
OK, let's check the source code (always a good idea) and see what happens.
好的,让我们检查源代码(总是一个好主意),看看会发生什么。
You send "test" via
你通过发送“测试”
SMTPClient sc;
sc.sendReceive("test"); // which is actually sent to your SMTPServer as "test\r\n"
Now, considering that this is a new SMTP conversation (see RFC5321 for everything you always wanted to know but were afraid to ask about such things) and "test" isn't a valid command VERB at this point in the conversation, you would expect to see an error returned by sendReceive()
.
现在,考虑到这是一个新的SMTP会话(请参阅RFC5321,了解您一直想知道的但却不敢问这些事情)并且“test”在对话的这一点上不是一个有效的命令VERB,你会期望查看sendReceive()返回的错误。
But since you're ignoring the SMTPClient.Response#75 returned from what should have been
但是因为你忽略了应该从原来返回的SMTPClient.Response#75
Response resp=SMTPClient.sendReceive()
you're missing out on both
你错过了两者
-
resp.code
(which I am sure is500 - Permanent Negative Completion reply / Syntax
- see the RFC above) and -
resp.message
describing the reason your command could not be fulfulled
resp.code(我肯定是500 - 永久否定完成回复/语法 - 参见上面的RFC)和
resp.message描述你的命令无法满足的原因
both of which are returned from CommandHandler#93.
这两个都是从CommandHandler#93返回的。
#1
0
OK, let's check the source code (always a good idea) and see what happens.
好的,让我们检查源代码(总是一个好主意),看看会发生什么。
You send "test" via
你通过发送“测试”
SMTPClient sc;
sc.sendReceive("test"); // which is actually sent to your SMTPServer as "test\r\n"
Now, considering that this is a new SMTP conversation (see RFC5321 for everything you always wanted to know but were afraid to ask about such things) and "test" isn't a valid command VERB at this point in the conversation, you would expect to see an error returned by sendReceive()
.
现在,考虑到这是一个新的SMTP会话(请参阅RFC5321,了解您一直想知道的但却不敢问这些事情)并且“test”在对话的这一点上不是一个有效的命令VERB,你会期望查看sendReceive()返回的错误。
But since you're ignoring the SMTPClient.Response#75 returned from what should have been
但是因为你忽略了应该从原来返回的SMTPClient.Response#75
Response resp=SMTPClient.sendReceive()
you're missing out on both
你错过了两者
-
resp.code
(which I am sure is500 - Permanent Negative Completion reply / Syntax
- see the RFC above) and -
resp.message
describing the reason your command could not be fulfulled
resp.code(我肯定是500 - 永久否定完成回复/语法 - 参见上面的RFC)和
resp.message描述你的命令无法满足的原因
both of which are returned from CommandHandler#93.
这两个都是从CommandHandler#93返回的。