【发布时间】:2015-02-25 03:53:42
【问题描述】:
当我运行客户端时,它应该向我的服务器发送一封电子邮件,然后我希望我的电子邮件服务器将电子邮件详细信息(收件人、发件人、端口、消息)打印到控制台。出于某种原因,在运行客户端后,服务器上没有任何明显的变化。
服务器
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] 信息 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);
}
}
}
客户端输出
运行:构建成功(总时间:0 秒)
版本是 3.1.7 来自https://code.google.com/p/subethasmtp/downloads/list
服务器需要 MyMessageHandlerFactory,我复制自:https://code.google.com/p/subethasmtp/wiki/SimpleExample
【问题讨论】:
标签: java email smtp jakarta-mail smtpclient