Java Code Examples for org.subethamail.smtp.server.SMTPServer#setHostName()

The following examples show how to use org.subethamail.smtp.server.SMTPServer#setHostName() . 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: SubethaEmailServer.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example 2
Source File: SakaiMessageHandlerFactory.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void init() {
    Objects.requireNonNull(rb, "ResourceLoader must be set");
    Objects.requireNonNull(serverConfigurationService, "ServerConfigurationService must be set");
    Objects.requireNonNull(entityManager, "EntityManager must be set");
    Objects.requireNonNull(aliasService, "AliasService must be set");
    Objects.requireNonNull(userDirectoryService, "UserDirectoryService must be set");
    Objects.requireNonNull(siteService, "SiteService must be set");
    Objects.requireNonNull(threadLocalManager, "ThreadLocalManager must be set");
    Objects.requireNonNull(contentHostingService, "ContentHostingService must be set");
    Objects.requireNonNull(mailArchiveService, "MailArchiveService must be set");
    Objects.requireNonNull(sessionManager, "SessionManager must be set");

    if (serverConfigurationService.getBoolean("smtp.enabled", false)) {
        server = new SMTPServer(this);

        server.setHostName(serverConfigurationService.getServerName());
        server.setPort(serverConfigurationService.getInt("smtp.port", 25));
        server.setSoftwareName("SubEthaSMTP - Sakai (" + serverConfigurationService.getString("sakai.version", "unknown") +
                ")");
        // We don't support smtp.dns.1 and smtp.dns.2
        server.setMaxConnections(100);
        server.start();
    }
}
 
Example 3
Source File: SakaiMessageHandlerFactory.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void init() {
    Objects.requireNonNull(rb, "ResourceLoader must be set");
    Objects.requireNonNull(serverConfigurationService, "ServerConfigurationService must be set");
    Objects.requireNonNull(entityManager, "EntityManager must be set");
    Objects.requireNonNull(aliasService, "AliasService must be set");
    Objects.requireNonNull(userDirectoryService, "UserDirectoryService must be set");
    Objects.requireNonNull(siteService, "SiteService must be set");
    Objects.requireNonNull(threadLocalManager, "ThreadLocalManager must be set");
    Objects.requireNonNull(contentHostingService, "ContentHostingService must be set");
    Objects.requireNonNull(mailArchiveService, "MailArchiveService must be set");
    Objects.requireNonNull(sessionManager, "SessionManager must be set");

    if (serverConfigurationService.getBoolean("smtp.enabled", false)) {
        server = new SMTPServer(this);

        server.setHostName(serverConfigurationService.getServerName());
        server.setPort(serverConfigurationService.getInt("smtp.port", 25));
        server.setSoftwareName("SubEthaSMTP - Sakai (" + serverConfigurationService.getString("sakai.version", "unknown") +
                ")");
        // We don't support smtp.dns.1 and smtp.dns.2
        server.setMaxConnections(100);
        server.start();
    }
}
 
Example 4
Source File: SslMailServer.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static void start() {
    smtpServer = new SMTPServer(messageHandlerFactory);
    smtpServer.setHostName(HOST);
    smtpServer.setPort(Integer.parseInt(PORT));
    smtpServer.start();

    log.info("Started mail server (" + smtpServer.getHostName() + ":" + smtpServer.getPort() + ")");
}
 
Example 5
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 6
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;
}