3 Replies Latest reply on Jun 8, 2014 11:16 PM by jaikiran

    Wildfly 8.1.0 Final Mail-Session always uses localhost

    tomas.kainbacher

      I’m trying to setup some simple mail service on Wildfly 8.1 with Gmail(for testing).

      For some reason, every time I transport the Mail, Wildfly tries to connect to localhost instead of the assigned outbound-socket!

       

      2014-06-07 13:59:01,353 ERROR [stderr] (default task-4) com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;

      2014-06-07 13:59:01,353 ERROR [stderr] (default task-4)   nested exception is:

      2014-06-07 13:59:01,353 ERROR [stderr] (default task-4)     java.net.ConnectException: Connection refused: connect

      2014-06-07 13:59:01,354 ERROR [stderr] (default task-4)     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1984)

      2014-06-07 13:59:01,354 ERROR [stderr] (default task-4)     at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:656)

      2014-06-07 13:59:01,354 ERROR [stderr] (default task-4)     at javax.mail.Service.connect(Service.java:345)

      2014-06-07 13:59:01,354 ERROR [stderr] (default task-4)     at javax.mail.Service.connect(Service.java:226)

      2014-06-07 13:59:01,354 ERROR [stderr] (default task-4)     at javax.mail.Service.connect(Service.java:175)

      2014-06-07 13:59:01,354 ERROR [stderr] (default task-4)     at javax.mail.Transport.send0(Transport.java:253)

      2014-06-07 13:59:01,354 ERROR [stderr] (default task-4)     at javax.mail.Transport.send(Transport.java:124)

       

      In standalone.xml:
      ...
      <mail-session name="java:jboss/mail/gmail" debug="true" jndi-name="java:jboss/mail/gmail">
        
      <smtp-server outbound-socket-binding-ref="mail-smtp" ssl="true" username="user@gmail.com" password="pass"/>
      </mail-session>
      ...
      <outbound-socket-binding name="mail-smtp">
        
      <remote-destination host="smtp.gmail.com" port="465"/>
      </outbound-socket-binding>

       

      As soon as I try to transport a mail I get the error!!
      What am I missing that it tries to connect to localhost?

        • 1. Re: Wildfly 8.1.0 Final Mail-Session always uses localhost
          wdfink

          Looks like the outbound-connection is not used.

          Could you see whether DEBUG or TRACE will show what happen?

          Also how the code look like?

          • 2. Re: Wildfly 8.1.0 Final Mail-Session always uses localhost
            tomas.kainbacher

            I'm creating the mail session in Java for now to get on with work, but i will recreate the error tomorrow(which is simple, config from above and code as below) and post the full output.
            The code looked something like this:

            ...

            @Stateless

            public class SendMail {

            @Resource(lookup = "java:jboss/mail/gmail")
            private Session mailSession;

            public String send() {
              
            MimeMessage m = new MimeMessage(mailSession);
              
            try {
              m
            .setRecipients(Message.RecipientType.TO, "test@mail.com");
              m
            .setContent("Test from Wildfly","text/plain");
              
            Transport.send(m);//throws exception
              
            } catch (MessagingException e) {
              e
            .printStackTrace();
              
            }
            ...

            • 3. Re: Wildfly 8.1.0 Final Mail-Session always uses localhost
              jaikiran
              Transport.send(m);//throws exception

              You are using the wrong method (the static one). The session you have injected isn't being used at all from what I see in that code. See the javadoc of that method for details. There's a getTransport() method on the Session class which is what you would want to use.


              Edit: I don't know why the editor decided to use brown colour for the text of my reply!