JBoss EAP authentication issue on SMTP mail

Solution Verified - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Issue

  • Our Java application deployed on JBoss Enterprise Application Platform (EAP) 6 cannot send out mail with JavaMail. We use Sendmail as SMTP server on Red Hat Enterprise Linux (RHEL). There is no log at all on Sendmail SMTP server side, and the exception stack trace on JBoss EAP side looks like this:
nested exception is javax.mail.AuthenticationFailedException: No authentication mechansims supported by both server and client
org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: No authentication mechansims supported by both server and client
        at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:392) ~[spring-context-support-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:306) ~[spring-context-support-3.0.6.RELEASE.jar:3.0.6.RELEASE]
        at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) ~[spring-context-support-3.0.6.RELEASE.jar:3.0.6.RELEASE]
******
Caused by: javax.mail.AuthenticationFailedException: No authentication mechansims supported by both server and client
        at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:756) ~[mail-1.4.4-redhat-1.jar!/:1.4.4-redhat-1]
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:669) ~[mail-1.4.4-redhat-1.jar!/:1.4.4-redhat-1]
        at javax.mail.Service.connect(Service.java:295) ~[mail-1.4.4-redhat-1.jar!/:1.4.4-redhat-1]
  • SMTP mail authentication is unsuccessful. I have setup SMTP server in EAP 6 standalone.xml file server is set up successfully in the standalone.xml file however it is giving me authentication failed while sending an email.

  • javax.mail.AuthenticationFailedException occurred in EAP. I got this error. How to avoid it?

javax.mail.AuthenticationFailedException
        at javax.mail.Service.connect(Service.java:306)
        at javax.mail.Service.connect(Service.java:156)
        at javax.mail.Service.connect(Service.java:105)
        at javax.mail.Transport.send0(Transport.java:168)
        at javax.mail.Transport.send(Transport.java:98)
        at com.example.MailSender.sendMail(MailSender.java:201)
  • We have a JBoss cluster with two nodes running on domain mode. For sending emails we are using "java:jboss/mail/Default" JNDI of the Mail subsystem. In each JBoss node, we have installed Sendmail.
<subsystem xmlns="urn:jboss:domain:mail:1.2">
    <mail-session name="default" jndi-name="java:jboss/mail/Default">
        <smtp-server outbound-socket-binding-ref="mail-smtp"/>
    </mail-session>
</subsystem>

    <outbound-socket-binding name="mail-smtp">
        <remote-destination host="localhost" port="25"/>
    </outbound-socket-binding>

Root Cause

According to official AuthenticationFailedException document, this exception is thrown when the connect method on a Store or Transport object fails due to an authentication failure (e.g., bad user name or password).

Diagnostic Steps

  1. Check the username and password for the SMTP server.

  2. Set up the property -Dmail.debug=true when launching the EAP JVM process

  3. Increase logging level for the SMTP server
    If using Sendmail in RHEL please follow article: How to debug Sendmail and increase the log level? to increase logging level and try to get some more logs on the Sendmail side.

  4. Check if SMTP server requires authentication
    If authentication is not required on the SMTP server side, please try to remove any username/password settings on the mail client side (within Java application) and use mail.smtp.auth=false
    If SMTP server does require authentication, please try to set mail.smtp.auth=true and use correct username/password to connect.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments