org.subethamail.smtp.MessageHandlerFactory Java Examples

The following examples show how to use org.subethamail.smtp.MessageHandlerFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SMTPServer.java    From subethasmtp with Apache License 2.0 6 votes vote down vote up
/**
 * Complex constructor.
 * 
 * @param authHandlerFact
 *            the {@link AuthenticationHandlerFactory} which performs
 *            authentication in the SMTP AUTH command. If null,
 *            authentication is not supported. Note that setting an
 *            authentication handler does not enforce authentication, it
 *            only makes authentication possible. Enforcing authentication
 *            is the responsibility of the client application, which usually
 *            enforces it only selectively. Use
 *            {@link Session#isAuthenticated} to check whether the client
 *            was authenticated in the session.
 * @param executorService
 *            the ExecutorService which will handle client connections, one
 *            task per connection. The SMTPServer will shut down this
 *            ExecutorService when the SMTPServer itself stops. If null, a
 *            default one is created by
 *            {@link Executors#newCachedThreadPool()}.
 */
public SMTPServer(MessageHandlerFactory msgHandlerFact, AuthenticationHandlerFactory authHandlerFact, ExecutorService executorService)
{
	this.messageHandlerFactory = msgHandlerFact;
	this.authenticationHandlerFactory = authHandlerFact;

	if (executorService != null) {
		this.executorService = executorService;
	} else {
		this.executorService = Executors.newCachedThreadPool();
	}

	try
	{
		this.hostName = InetAddress.getLocalHost().getCanonicalHostName();
	}
	catch (UnknownHostException e)
	{
		this.hostName = UNKNOWN_HOSTNAME;
	}

	this.commandHandler = new CommandHandler();
}
 
Example #2
Source File: ListenSMTP.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #3
Source File: SMTPServer.java    From subethasmtp with Apache License 2.0 4 votes vote down vote up
/**
 * Simple constructor.
 */
public SMTPServer(MessageHandlerFactory handlerFactory)
{
	this(handlerFactory, null, null);
}
 
Example #4
Source File: SMTPServer.java    From subethasmtp with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor with {@link AuthenticationHandlerFactory}.
 */
public SMTPServer(MessageHandlerFactory handlerFactory, AuthenticationHandlerFactory authHandlerFact)
{
    this(handlerFactory, authHandlerFact, null);
}
 
Example #5
Source File: SMTPServer.java    From subethasmtp with Apache License 2.0 4 votes vote down vote up
/**
 * @return the factory for message handlers, cannot be null
 */
public MessageHandlerFactory getMessageHandlerFactory()
{
	return this.messageHandlerFactory;
}
 
Example #6
Source File: SMTPServer.java    From subethasmtp with Apache License 2.0 4 votes vote down vote up
/** */
public void setMessageHandlerFactory(MessageHandlerFactory fact)
{
	this.messageHandlerFactory = fact;
}
 
Example #7
Source File: SubmissionServer.java    From mireka with Apache License 2.0 4 votes vote down vote up
public SubmissionServer(MessageHandlerFactory handlerFactory) {
    super(handlerFactory);
    setPort(587);
}
 
Example #8
Source File: SMTPServer.java    From mireka with Apache License 2.0 4 votes vote down vote up
public SMTPServer(MessageHandlerFactory handlerFactory) {
    super(handlerFactory);
    setSoftwareName("Mireka " + Version.getVersion());
}
 
Example #9
Source File: ListenSMTP.java    From nifi with Apache License 2.0 4 votes vote down vote up
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(SslContextFactory.ClientAuth.valueOf(clientAuth));
            SSLSocketFactory socketFactory = sslContext.getSocketFactory();
            SSLSocket sslSocket = (SSLSocket) (socketFactory.createSocket(socket, remoteAddress.getHostName(), socket.getPort(), true));
            sslSocket.setUseClientMode(false);

            if (SslContextFactory.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;
}