public static void startWithAuth(int port) { SMTPServer server = new SMTPServer(new SimpleMessageListenerAdapter(new MyMessageListener())); server.setPort(port); UsernamePasswordValidator validator = (s, s1) -> { if (!"username".equalsIgnoreCase(s) || !"password".equalsIgnoreCase(s1)) { throw new LoginFailedException(); } }; server.setAuthenticationHandlerFactory(new PlainAuthenticationHandlerFactory(validator)); server.start(); }
final SMTPServer smtpServer = sslContextService == null ? new SMTPServer(messageHandlerFactory) : new SMTPServer(messageHandlerFactory) { @Override public SSLSocket createSSLSocket(Socket socket) throws IOException { 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());
public static void start(int port) { SMTPServer smtpServer = new SMTPServer(new SimpleMessageListenerAdapter(new MyMessageListener())); smtpServer.setPort(port); smtpServer.start(); }
@Override public void startup() { serverImpl = new SMTPServer(new HandlerFactory()); // MER - May need to override SMTPServer.createSSLSocket to specify non default keystore. serverImpl.setPort(getPort()); serverImpl.setHostName(getDomain()); serverImpl.setMaxConnections(getMaxConnections()); serverImpl.setHideTLS(isHideTLS()); serverImpl.setEnableTLS(isEnableTLS()); serverImpl.setRequireTLS(isRequireTLS()); if(isAuthenticate()) { AuthenticationHandlerFactory authenticationHandler = new EasyAuthenticationHandlerFactory(new AlfrescoLoginUsernamePasswordValidator()); serverImpl.setAuthenticationHandlerFactory(authenticationHandler); } serverImpl.start(); log.info("Inbound SMTP Email Server has started successfully, on hostName:" + getDomain() + "port:" + getPort()); }
public void doTest() throws Exception { Wiser wiser = new Wiser(); SMTPServer smtpServer = createServer(new SimpleMessageListenerAdapter(wiser)); smtpServer.setHostName("localhost"); smtpServer.setPort(5000); TestPluginLifeCycle lifeCycle = createLifeCycle(); try { lifeCycle.start(); smtpServer.start(); execute(lifeCycle, wiser); } finally { smtpServer.stop(); lifeCycle.stop(); } } }
/** * Start the SMTP Embedded Server; called by the container during deployment * * @throws Exception */ @PostConstruct public void startup() throws Exception { server = new SMTPServer(new SimpleMessageListenerAdapter(listener)); server.setBindAddress(InetAddress.getLoopbackAddress()); server.setPort(BIND_PORT); server.start(); }
public void start() { // start the smtp server! SMTPServer server = new SMTPServer(handlerFactory); server.setSoftwareName("MockMock SMTP Server version " + AppStarter.VERSION_NUMBER); server.setPort(port); try { System.out.println("Starting MockMock on port " + port); server.start(); } catch (Exception e) { System.err.println("Could not start MockMock. Maybe port " + port + " is already in use?"); } } }
/** * Starts the SMTP Server */ public void start() { this.server.start(); }
protected void initSmtpReceiver() { Collection<MessageListener> listeners = new ArrayList<MessageListener>(1); listeners.add(this); if( enableTls ) { log.info("Creating TLS enabled server"); this.smtpReceivingServer = new SMTPServer(listeners); } else { log.info("Creating TLS DIS-abled server"); this.smtpReceivingServer = new TlsDisabledSmtpServer(listeners); } this.smtpReceivingServer.setPort(smtpPort); this.smtpReceivingServer.setMaxConnections(30000); CommandHandler cmdHandler = this.smtpReceivingServer.getCommandHandler(); MessageListenerAdapter mla = (MessageListenerAdapter) smtpReceivingServer.getMessageHandlerFactory(); mla.setAuthenticationHandlerFactory(null); }
/** Stops the SMTP Server */ public void stop() { this.server.stop(); }
/** * Starts the server on the port and address specified in parameters. * * @param port the SMTP port to be opened. * @param bindAddress the address to bind to. null means bind to all. * @throws BindPortException when the port can't be opened. * @throws OutOfRangePortException when port is out of range. * @throws IllegalArgumentException when port is out of range. */ public void startServer(int port, InetAddress bindAddress) throws BindPortException, OutOfRangePortException { LOGGER.debug("Starting server on port {}", port); try { smtpServer.setBindAddress(bindAddress); smtpServer.setPort(port); smtpServer.start(); } catch (RuntimeException exception) { if (exception.getMessage().contains("BindException")) { // Can't open port LOGGER.error("{}. Port {}", exception.getMessage(), port); throw new BindPortException(exception, port); } else if (exception.getMessage().contains("out of range")) { // Port out of range LOGGER.error("Port {} out of range.", port); throw new OutOfRangePortException(exception, port); } else { // Unknown error LOGGER.error("", exception); throw exception; } } }
/** * Create a new SMTP server with this class as the listener. * The default port is set to 25. Call setPort()/setHostname() before * calling start(). */ public Wiser() { Collection<MessageListener> listeners = new ArrayList<MessageListener>(1); listeners.add(this); this.server = new SMTPServer(listeners); this.server.setPort(25); ((MessageListenerAdapter)server.getMessageHandlerFactory()) .setAuthenticationHandlerFactory(new AuthHandlerFactory()); }
/** * Create a new SMTP server with this class as the listener. The default port is set to 25. Call * setPort()/setHostname() before calling start(). */ public NanoSMTP() { Collection<MessageListener> listeners = new ArrayList<MessageListener>(1); listeners.add(this); this.server = new SMTPServer(listeners); this.server.setPort(25); this.server.setMaxConnections(30000); }
public SubethaSMTP(MessageHandlerFactory factory, int port) { this.smtpServer = new SMTPServer(factory); smtpServer.setPort(port); }
protected SMTPServer createServer(MessageHandlerFactory mhf) { return new SMTPServer(mhf); }
/** * The port that the server should listen on. * @param port */ public void setPort(int port) { this.server.setPort(port); }
@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); } } context.yield();//nothing really to do here since threading managed by smtp server sessions }
"220 " + this.server.getHostName() + " ESMTP " + this.server.getSoftwareName()); this.server.getCommandHandler().handleCommand(this, line); } catch (DropConnectionException ex) { this.sendResponse(ex.getErrorResponse());