use of org.subethamail.smtp.server.SMTPServer in project fake-smtp-server by gessnerfl.
the class SmtpServerConfiguratorTest method shouldConfigureBasicParameters.
@Test
public void shouldConfigureBasicParameters() {
final Integer port = 1234;
final InetAddress bindingAddress = mock(InetAddress.class);
when(fakeSmtpConfigurationProperties.getPort()).thenReturn(port);
when(fakeSmtpConfigurationProperties.getBindAddress()).thenReturn(bindingAddress);
final SMTPServer smtpServer = mock(SMTPServer.class);
sut.configure(smtpServer);
verify(smtpServer).setPort(port);
verify(smtpServer).setBindAddress(bindingAddress);
verify(smtpServer, never()).setAuthenticationHandlerFactory(any(AuthenticationHandlerFactory.class));
}
use of org.subethamail.smtp.server.SMTPServer in project motech by motech.
the class EmailChannelBundleIT method testEmailSentOnSendEmailEvent.
@Test
public void testEmailSentOnSendEmailEvent() throws MessagingException, IOException, InterruptedException {
SMTPServer smtpServer = new SMTPServer(new SimpleMessageListenerAdapter(this));
new Wait(new ContextPublishedWaitCondition(bundleContext, "org.motechproject.motech-platform-event"), 5000).start();
new Wait(new ContextPublishedWaitCondition(bundleContext), 5000).start();
try {
smtpServer.setPort(8099);
smtpServer.start();
String messageText = "test message";
String from = "testfromaddress";
String to = "testtoaddress";
String subject = "test subject";
Map<String, Object> values = new HashMap<>();
values.put("fromAddress", from);
values.put("toAddress", to);
values.put("message", messageText);
values.put("subject", subject);
eventRelay.sendEventMessage(new MotechEvent(SendEmailConstants.SEND_EMAIL_SUBJECT, values));
new Wait(lock, this, 100, 60000).start();
assertTrue("Message not received", messageReceived);
assertNotNull(receivedMessageText);
assertEquals(messageText, receivedMessageText.trim());
} finally {
smtpServer.stop();
}
}
use of org.subethamail.smtp.server.SMTPServer in project nifi by apache.
the class ListenSMTP method prepareServer.
private SMTPServer prepareServer(final ProcessContext context, final ProcessSessionFactory sessionFactory) {
final int port = context.getProperty(SMTP_PORT).asInteger();
final String host = context.getProperty(SMTP_HOSTNAME).getValue();
final ComponentLog log = getLogger();
final int maxMessageSize = context.getProperty(SMTP_MAXIMUM_MSG_SIZE).asDataSize(DataUnit.B).intValue();
// create message handler factory
final MessageHandlerFactory messageHandlerFactory = (final MessageContext mc) -> {
return new SmtpConsumer(mc, sessionFactory, port, host, log, maxMessageSize);
};
// create smtp server
final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
final SMTPServer smtpServer = sslContextService == null ? new SMTPServer(messageHandlerFactory) : new SMTPServer(messageHandlerFactory) {
@Override
public SSLSocket createSSLSocket(Socket socket) throws IOException {
InetSocketAddress remoteAddress = (InetSocketAddress) socket.getRemoteSocketAddress();
String clientAuth = context.getProperty(CLIENT_AUTH).getValue();
SSLContext sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.valueOf(clientAuth));
SSLSocketFactory socketFactory = sslContext.getSocketFactory();
SSLSocket sslSocket = (SSLSocket) (socketFactory.createSocket(socket, remoteAddress.getHostName(), socket.getPort(), true));
sslSocket.setUseClientMode(false);
if (SSLContextService.ClientAuth.REQUIRED.toString().equals(clientAuth)) {
this.setRequireTLS(true);
sslSocket.setNeedClientAuth(true);
}
return sslSocket;
}
};
if (sslContextService != null) {
smtpServer.setEnableTLS(true);
} else {
smtpServer.setHideTLS(true);
}
smtpServer.setSoftwareName("Apache NiFi SMTP");
smtpServer.setPort(port);
smtpServer.setMaxConnections(context.getProperty(SMTP_MAXIMUM_CONNECTIONS).asInteger());
smtpServer.setMaxMessageSize(maxMessageSize);
smtpServer.setConnectionTimeout(context.getProperty(SMTP_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue());
if (context.getProperty(SMTP_HOSTNAME).isSet()) {
smtpServer.setHostName(context.getProperty(SMTP_HOSTNAME).getValue());
}
return smtpServer;
}
use of org.subethamail.smtp.server.SMTPServer in project nifi by apache.
the class ListenSMTP method onTrigger.
@Override
public void onTrigger(final ProcessContext context, final ProcessSessionFactory sessionFactory) throws ProcessException {
if (smtp == null) {
try {
final SMTPServer server = prepareServer(context, sessionFactory);
server.start();
getLogger().debug("Started SMTP Server on port " + server.getPort());
smtp = server;
} catch (final Exception ex) {
// have to catch exception due to awkward exception handling in subethasmtp
smtp = null;
getLogger().error("Unable to start SMTP server due to " + ex.getMessage(), ex);
}
}
// nothing really to do here since threading managed by smtp server sessions
context.yield();
}
use of org.subethamail.smtp.server.SMTPServer in project vertx-examples by vert-x3.
the class LocalSmtpServer method start.
public static void start(int port) {
SMTPServer smtpServer = new SMTPServer(new SimpleMessageListenerAdapter(new MyMessageListener()));
smtpServer.setPort(port);
smtpServer.start();
}
Aggregations