force Tomcat to use jakarta.mail instead of java mail with TLS

89 Views Asked by At

I'm trying to send mail using office365 in a java application with Jakarta Mail version 1.6.7, and it works fine on my windows machine.

Using the same application on Ubuntu 22 I catch this error: javax.mail.MessagingException: Can't send command to SMTP host

Enabling debug of SMTP I've notice a strange behaviour on Ubuntu:

EmailController   : {mail.debug=true, mail.smtp.ssl.trust=*, mail.smtp.port=587, mail.smtp.auth=true, mail.smtp.starttls.enable=true, mail.smtp.host=smtp.office365.com, mail.smtp.ssl.protocols=TLSv1.3}
DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException: /usr/lib/jvm/java-17-openjdk-amd64/lib/javamail.providers (No such file or directory)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc],com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc],imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,co
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoadedDEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: /usr/lib/jvm/java-17-openjdk-amd64/lib/javamail.address.map (No such file or directory)
EmailController   : Message is ready

On Windows 11:

EmailController   : {mail.debug=true, mail.smtp.port=587, mail.smtp.auth=true, mail.smtp.starttls.enable=true, mail.smtp.host=smtp.office365.com, mail.smtp.ssl.protocols=TLSv1.3}
DEBUG: Jakarta Mail version 1.6.7
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers

Why Tomcat is not using in the first case on Ubuntu jakarta.mail lib?

I know that tls v1.3 is not supported by java.mail before 1.5.x version so I think this is the problem. How can I force server to use version of jakarta mail in my application?

0

There are 0 best solutions below