Enable TLS for outbound mail in EAP 7

Latest response

Howdy,

How can I enable STARTTLS in the SMTP connector (mail-smtp, outbound remote) to connect to Microsoft relay host smtp.office365.com ?
I need to send outgoing mail.
Thanks a lot for your feedback.
Luc

This is my standalone.xml

<outbound-socket-binding name="mail-smtp">
    <remote-destination host="smtp.gmail.com" port="465"/>
</outbound-socket-binding>

<subsystem xmlns="urn:jboss:domain:mail:2.0">
    <mail-session name="default" jndi-name="java:jboss/mail/Default">
     <smtp-server password="*************" username="it-services@ladbrokes.be" ssl="true" outbound-socket-binding-ref="mail-smtp"/>
    </mail-session>
</subsystem>

Responses

Hello Luc,

Have you been able to solve this issue. I'm having a similar issue and RH team suggested removing the ssl ="true" and adding tls = "true" instead. Just curious how you were able to get around this issue.

Thanks,

Hi Prajith, I created a workaround like this in standalone.xml

<subsystem xmlns="urn:jboss:domain:mail:2.0">
            <mail-session name="default" jndi-name="java:jboss/mail/Default" debug="false">
                <smtp-server password="**********" username="memyselfandi@acme.com" tls="true" outbound-socket-binding-ref="mail-smtp"/>
            </mail-session>
        </subsystem>
<outbound-socket-binding name="mail-smtp">
            <remote-destination host="smtp.office365.com" port="587"/>
</outbound-socket-binding>

Unfortunately I was not able to inject other mail properties into my @Resource MailSession so I had to create my own mail session and add custom properties in my bean (which is not ideal).

@Stateless
public class MailService {
    @Resource(lookup="java:jboss/mail/Default")
    private Session defaultSession;
    private Session mailSession;

    /**
     * Modify the default session by adding timeouts and encrypted password. <br/>
     * This violates the Resource but there is no alternative to add properties to the mail Session.
     */
    @PostConstruct
    public void setMailSession() {
        MailSessionConfig config = BeanLocator.getInstance().getMailSessionConfig();
        Properties props = defaultSession.getProperties();
        props.setProperty("mail.smtp.connectiontimeout", config.getConnectionTimeout() + "");
        props.setProperty("mail.smtp.timeout", config.getReadTimeout() + "");

        try {
            SecretKey key = KeyStore.getInstance(new File(config.getKeyfile())).getKeyModel().getKey();
            String decryptedPassword = AESEncryptionHelper.decrypt(config.getPassword(), key);
            Authenticator auth = new SMTPAuthenticator(config.getUsername(), decryptedPassword);
            this.mailSession = Session.getInstance(props, auth);
        }
        catch (IOException ioex) {
            logger.warn("Unable to set SMTP service encrypted password, using default session (without timeouts); message={}", ioex.getMessage());
            this.mailSession = defaultSession;
        }

    }