您可以通过使用org.apache.james.smtpserver.netty.SMTPServer
. 为此,您将需要一些依赖项。
对于Gradle:
implementation group: 'org.apache.james', name: 'james-server-protocols-smtp', version: '3.5.0'
implementation group: 'org.apache.james', name: 'metrics-api', version: '3.5.0'
implementation group: 'org.apache.james', name: 'metrics-logger', version: '3.5.0'
implementation group: 'org.apache.james.protocols', name: 'protocols-netty', version: '3.5.0'
对于Maven:
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>james-server-protocols-smtp</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.james.protocols</groupId>
<artifactId>protocols-netty</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>metrics-api</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>metrics-logger</artifactId>
<version>3.5.0</version>
</dependency>
SMTPServer
是指标的一部分,james-server-protocols-smtp
但其他指标是必需的。
您的接口的示例实现可能如下所示:
public class MySmtpServer implements TestServer {
private final SMTPServer smtpServer;
public MySmtpServer(final int port) {
MetricFactory metricFactory = new DefaultMetricFactory();
SmtpMetrics smtpMetrics = new SmtpMetricsImpl(metricFactory);
SMTPServer smtpServer = new SMTPServer(smtpMetrics);
smtpServer.setListenAddresses(new InetSocketAddress(port));
this.smtpServer = smtpServer;
}
@Override
public void start() {
smtpServer.start();
}
@Override
public void stop() {
smtpServer.stop();
}
}