當我運行客戶端時,它應該發送一封電子郵件到我的服務器,然後我想讓我的電子郵件服務器將電子郵件的詳細信息(到,從,端口,消息)打印到控制檯。出於某種原因運行客戶端後,服務器上沒有任何明顯的情況發生。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
哦,關於你的'IOException' try/catch,事務不會失敗。相反,如果您選擇關注它,它會盡職盡責地回報您的問題。 :-) –
所以,我是這個圖書館的全新人物,從未碰過它。爲了讓我的服務器打印出客戶端的電子郵件,你可以告訴我需要做哪些基本的代碼級別更改? – ThreaT
只需跟進,有沒有機會看看我以前的評論? – ThreaT