SubethaSmtp是否将电子邮件存储在某个地方



我使用SubethaSmtp库作为电子邮件服务器,到目前为止,我已经能够运行该服务器并通过发送电子邮件对其进行测试。电子邮件信息打印在输出中。据我所知,smtp协议是用来发送电子邮件的。IMAP协议用于接收电子邮件。我的问题是,SubethaSmtp是否将电子邮件存储在某个地方(例如数据库或文件(?一般来说,我需要SubethaSmtp服务器以外的服务器来接收电子邮件吗?这两个协议之间的关系是什么?

我的代码是用以下两个Java类编写的:

BasicSMTPServer类:

package com.sojoodi;
import org.subethamail.smtp.server.SMTPServer;

public class BasicSMTPServer {
public static void main(String[] args) {
MyMessageHandlerFactory myFactory = new MyMessageHandlerFactory();
SMTPServer smtpServer = new SMTPServer(myFactory);
smtpServer.setPort(25000);
smtpServer.start();
System.out.println("smtpServer = " + smtpServer);
System.out.println("HostName = " + smtpServer.getHostName());
}
}

和MyMessageHandlerFactory类:

package com.sojoodi;
import org.subethamail.smtp.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class MyMessageHandlerFactory implements MessageHandlerFactory {
public MessageHandler create(MessageContext ctx) {
return new Handler(ctx);
}
class Handler implements MessageHandler {
MessageContext ctx;
public Handler(MessageContext ctx) {
this.ctx = ctx;
}
public void from(String from) throws RejectException {
System.out.println("FROM:"+from);
}
public void recipient(String recipient) throws RejectException {
System.out.println("RECIPIENT:"+recipient);
}
public void data(InputStream data) throws IOException {
System.out.println("MAIL DATA");
System.out.println("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");
System.out.println(this.convertStreamToString(data));
System.out.println("= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =");
}
public void done() {
System.out.println("Finished");
}
public String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "n");
}
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
}
}

也许你可以查看SubEtha SMTP和Spring Boot的接收电子邮件帖子,如果你有关于存储的问题,你可以查看相关代码库中的问题部分,因为存在与你相同的问题。

最新更新