Skip to content

Custom socketFactory is not taken into account with the SMTPS transport #611

@gerardnico

Description

@gerardnico

The bug is here

props.put("mail.smtp.ssl.socketFactory", serverConfig.getCustomSSLFactoryInstance());

The Prop is ok for a SMTP transport but for a SMTPS transport it should be

props.put("mail.smtps.ssl.socketFactory", serverConfig.getCustomSSLFactoryInstance());

The angus library expects: mail.smtps.ssl.socketFactory or mail.smtps.socketFactory
when the transport is SMTPS and not mail.smtp.ssl.socketFactory or mail.smtp.socketFactory

The Angus code can be seen here
where they use a prefix (ie mail.smtps for SMTPS transport)

Object sfo = props.get(prefix + ".ssl.socketFactory");

A mailer defined has:

Mailer mailer = MailerBuilder
                .withSMTPServer("localhost", SmtpService.PORT_587)
                .withTransportStrategy(TransportStrategy.SMTPS)
                .withCustomSSLFactoryInstance(sslFactory)
                .buildMailer()

will therefore not work.

Note that for a custom SSLFactory to work, Angus expects also no value in the prop mail.smtps.ssl.trust, otherwise it creates its own socket as seen here

So I needed to add this 2 lines to make it work:

Session session = mailer.getSession();
Properties properties = session.getProperties();
properties.put("mail.smtps.ssl.socketFactory", sslFactory);
properties.remove("mail.smtps.ssl.trust");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions