Wildfly -9 javax.mail is not working

2020-04-14 09:33发布

问题:

I am making use of Wildfly 9.0.0 Final and javax.mail api in my application.

I am getting the following log:

2015-07-27 15:08:16,318 CONFIG [javax.mail] (default task-17) 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,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
2015-07-27 15:08:16,318 CONFIG [javax.mail] (default task-17) 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,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
2015-07-27 15:08:16,319 CONFIG [javax.mail] (default task-17) successfully loaded resource: /META-INF/javamail.default.address.map
2015-07-27 15:08:16,340 DEBUG [class com.bodhtree.nexus.util.mail.Mail] (default task-17) TO : jobseeker403@gmail.com
2015-07-27 15:08:16,341 DEBUG [class com.bodhtree.nexus.util.mail.Mail] (default task-17) ccAddresses : 
2015-07-27 15:08:16,341 DEBUG [class com.bodhtree.nexus.util.mail.Mail] (default task-17) bccAddresses : 
2015-07-27 15:08:16,341 DEBUG [class com.bodhtree.nexus.util.mail.Mail] (default task-17) messagesender : support@smarthires.com
2015-07-27 15:08:16,341 DEBUG [class com.bodhtree.nexus.util.mail.Mail] (default task-17) I subjectFriend recommends "Admin" opening at "ALECTO HEALTHCARE"
2015-07-27 15:08:16,346 DEBUG [class com.bodhtree.nexus.util.mail.Mail] (default task-17) Message: javax.mail.internet.MimeMessage@6be2cbe7
2015-07-27 15:08:16,357 FINE  [javax.activation] (default task-17) MailcapCommandMap: load HOME
2015-07-27 15:08:16,359 FINE  [javax.activation] (default task-17) new MailcapFile: file C:\Users\kiran.MAHATHI\.mailcap
2015-07-27 15:08:16,360 FINE  [javax.activation] (default task-17) MailcapCommandMap: load SYS
2015-07-27 15:08:16,360 FINE  [javax.activation] (default task-17) new MailcapFile: file C:\Program Files\Java\jdk1.8.0_45\jre\lib\mailcap
2015-07-27 15:08:16,360 FINE  [javax.activation] (default task-17) MailcapCommandMap: load JAR
2015-07-27 15:08:16,362 FINE  [javax.activation] (default task-17) MailcapCommandMap: getResources
2015-07-27 15:08:16,362 FINE  [javax.activation] (default task-17) MailcapCommandMap: URL vfs:/C:/Work/wildfly-9.0.0.Final/bin/content/SmarthiresMaven.war/WEB-INF/lib/mail-1.4.jar/META-INF/mailcap
2015-07-27 15:08:16,363 FINE  [javax.activation] (default task-17) new MailcapFile: InputStream
2015-07-27 15:08:16,364 FINE  [javax.activation] (default task-17) parse: text/plain;;      x-java-content-handler=com.sun.mail.handlers.text_plain
2015-07-27 15:08:16,364 FINE  [javax.activation] (default task-17)   Type: text/plain
2015-07-27 15:08:16,364 FINE  [javax.activation] (default task-17)     Command: content-handler, Class: com.sun.mail.handlers.text_plain
2015-07-27 15:08:16,364 FINE  [javax.activation] (default task-17) parse: text/html;;       x-java-content-handler=com.sun.mail.handlers.text_html
2015-07-27 15:08:16,365 FINE  [javax.activation] (default task-17)   Type: text/html
2015-07-27 15:08:16,365 FINE  [javax.activation] (default task-17)     Command: content-handler, Class: com.sun.mail.handlers.text_html
2015-07-27 15:08:16,365 FINE  [javax.activation] (default task-17) parse: text/xml;;        x-java-content-handler=com.sun.mail.handlers.text_xml
2015-07-27 15:08:16,365 FINE  [javax.activation] (default task-17)   Type: text/xml
2015-07-27 15:08:16,365 FINE  [javax.activation] (default task-17)     Command: content-handler, Class: com.sun.mail.handlers.text_xml
2015-07-27 15:08:16,365 FINE  [javax.activation] (default task-17) parse: multipart;;       x-java-content-handler=com.sun.mail.handlers.multipart_mixed; x-java-fallback-entry=true
2015-07-27 15:08:16,365 FINE  [javax.activation] (default task-17)   Type: multipart
2015-07-27 15:08:16,366 FINE  [javax.activation] (default task-17)     Command: content-handler, Class: com.sun.mail.handlers.multipart_mixed
2015-07-27 15:08:16,366 FINE  [javax.activation] (default task-17) parse: message/rfc822;;  x-java-content-handler=com.sun.mail.handlers.message_rfc822
2015-07-27 15:08:16,366 FINE  [javax.activation] (default task-17)   Type: message/rfc822
2015-07-27 15:08:16,366 FINE  [javax.activation] (default task-17)     Command: content-handler, Class: com.sun.mail.handlers.message_rfc822
2015-07-27 15:08:16,366 FINE  [javax.activation] (default task-17) MailcapCommandMap: successfully loaded mailcap file from URL: vfs:/C:/Work/wildfly-9.0.0.Final/bin/content/SmarthiresMaven.war/WEB-INF/lib/mail-1.4.jar/META-INF/mailcap
2015-07-27 15:08:16,366 FINE  [javax.activation] (default task-17) MailcapCommandMap: load DEF
2015-07-27 15:08:16,367 FINE  [javax.activation] (default task-17) new MailcapFile: InputStream
2015-07-27 15:08:16,367 FINE  [javax.activation] (default task-17) parse: image/gif;;       x-java-view=com.sun.activation.viewers.ImageViewer
2015-07-27 15:08:16,367 FINE  [javax.activation] (default task-17)   Type: image/gif
2015-07-27 15:08:16,368 FINE  [javax.activation] (default task-17)     Command: view, Class: com.sun.activation.viewers.ImageViewer
2015-07-27 15:08:16,368 FINE  [javax.activation] (default task-17) parse: image/jpeg;;      x-java-view=com.sun.activation.viewers.ImageViewer
2015-07-27 15:08:16,368 FINE  [javax.activation] (default task-17)   Type: image/jpeg
2015-07-27 15:08:16,368 FINE  [javax.activation] (default task-17)     Command: view, Class: com.sun.activation.viewers.ImageViewer
2015-07-27 15:08:16,368 FINE  [javax.activation] (default task-17) parse: text      x-java-view=com.sun.activation.viewers.TextViewer
2015-07-27 15:08:16,368 FINE  [javax.activation] (default task-17)   Type: text
2015-07-27 15:08:16,368 FINE  [javax.activation] (default task-17)     Command: view, Class: com.sun.activation.viewers.TextViewer
2015-07-27 15:08:16,370 FINE  [javax.activation] (default task-17) parse: text  x-java-edit=com.sun.activation.viewers.TextEditor
2015-07-27 15:08:16,371 FINE  [javax.activation] (default task-17)   Type: text
2015-07-27 15:08:16,371 FINE  [javax.activation] (default task-17)     Command: edit, Class: com.sun.activation.viewers.TextEditor
2015-07-27 15:08:16,371 FINE  [javax.activation] (default task-17) Merging commands for type text
2015-07-27 15:08:16,372 FINE  [javax.activation] (default task-17) MailcapCommandMap: successfully loaded mailcap file: /META-INF/mailcap.default
2015-07-27 15:08:16,372 FINE  [javax.activation] (default task-17) MailcapCommandMap: createDataContentHandler for text/html
2015-07-27 15:08:16,372 FINE  [javax.activation] (default task-17)   search DB #1
2015-07-27 15:08:16,373 FINE  [javax.activation] (default task-17)     got content-handler
2015-07-27 15:08:16,373 FINE  [javax.activation] (default task-17)       class com.sun.mail.handlers.text_html
2015-07-27 15:08:16,385 FINE  [javax.mail] (default task-17) getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
2015-07-27 15:08:16,448 FINE  [com.sun.mail.smtp] (default task-17) need username and password for authentication
2015-07-27 15:08:16,449 FINE  [com.sun.mail.smtp] (default task-17) useEhlo true, useAuth true
2015-07-27 15:08:16,450 FINE  [com.sun.mail.smtp] (default task-17) trying to connect to host "smtp.gmail.com", port 465, isSSL false
2015-07-27 15:09:24,610 DEBUG [org.jboss.ejb.client.txn] (Periodic Recovery) Send recover request for transaction origin node identifier 1 to EJB receiver with node name kirankumar
2015-07-27 15:09:34,613 DEBUG [org.jboss.ejb.client.txn] (Periodic Recovery) Send recover request for transaction origin node identifier 1 to EJB receiver with node name kirankumar
2015-07-27 15:11:34,620 DEBUG [org.jboss.ejb.client.txn] (Periodic Recovery) Send recover request for transaction origin node identifier 1 to EJB receiver with node name kirankumar
2015-07-27 15:11:44,621 DEBUG [org.jboss.ejb.client.txn] (Periodic Recovery) Send recover request for transaction origin node identifier 1 to EJB receiver with node name kirankumar

And I am not using any kind of EJB in my application. And tried with Wildfly 8.2.0 and its works for me. but my application requires Wildfly 9. I could not find what was causing the issue.

回答1:

Finally I found it is because of mail module in Wildfly9.0.0.Final. We can do this as temporary solution.And it works for me.

Open standalone-ha.xml from <wildfly-9.0.0.Final-Home>\standalone\configuration

Releace the following

<subsystem xmlns="urn:jboss:domain:mail:2.0">
         <mail-session name="default" jndi-name="java:jboss/mail/Default">
                <smtp-server outbound-socket-binding-ref="mail-smtp"/>
          </mail-session>
  </subsystem>

With

<subsystem xmlns="urn:jboss:domain:mail:2.0">
     <mail-session name="default" jndi-name="java:jboss/mail/Default">
      </mail-session>
 </subsystem>

Now open “module.xml” from <wildfly-9.0.0.Final-Home>\modules\system\layers\base\javax\mail\api\main

Replace the following line

<resource-root path="javax.mail-1.5.3.jar"/>

With

<resource-root path="javax.mail-1.5.1.jar"/>

And copy the “javax.mail-1.5.1.jar” form

<wildfly-8.2.0.Final -Home>\modules\system\layers\base\javax\mail\api\main

To

<wildfly-9.0.0.Final-Home>\modules\system\layers\base\javax\mail\api\main

And remove “javax.mail-1.5.3.jar”

from the

<wildfly-9.0.0.Final-Home>\modules\system\layers\base\javax\mail\api\main

And restart the server. It works for me.



回答2:

You're trying to connect to smtp.gmail.com on port 465, which is an SSL port, but JavaMail doesn't think you want to use SSL. You're probably failing in the SSL protocol negotiation. Something is wrong with how you're setting the configuration for the JavaMail Session that you're using.