title: Wildfly Mail-Session always uses localhost
body: <p>I’m trying to setup some simple mail service on <code>Wildfly 8.1</code> with Gmail(for testing).<br>
  For some reason, every time I transport the Mail, Wildfly tries to connect to <code>localhost</code> instead of the assigned <code>outbound-socket</code>!</p>
  
  <p>Error:</p>
  
  <pre><code>13:22:34,164 ERROR [stderr] (default task-22) com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 25; timeout -1;
  13:22:34,164 ERROR [stderr] (default task-22)   nested exception is:
  13:22:34,165 ERROR [stderr] (default task-22)   java.net.ConnectException: Connection refused: connect
  13:22:34,165 ERROR [stderr] (default task-22)   at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1984)
  </code></pre>
  
  <p>standalone.xml</p>
  
  <pre><code>...
  &lt;mail-session name="java:jboss/mail/gmail" debug="true" jndi-name="java:jboss/mail/gmail"&gt;
      &lt;smtp-server outbound-socket-binding-ref="mail-smtp" ssl="true" username="user@gmail.com" password="pass"/&gt;
  &lt;/mail-session&gt;
  ...
  &lt;outbound-socket-binding name="mail-smtp"&gt;
      &lt;remote-destination host="smtp.gmail.com" port="465"/&gt;
  &lt;/outbound-socket-binding&gt;
  </code></pre>
  
  <p>Then I just try and send a mail:</p>
  
  <pre><code>@Stateless
  public class SendMail {
  
  @Resource(mappedName = "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();
      }
  ...
  </code></pre>
  
  <p>I've tried "<code>name</code>" &amp; "<code>lookup</code>" in the <code>@Resource</code> annotation but it just keeps wanting to connect to <code>localhost</code>, for which there isn't even an <code>outbound-socket</code>.<br></p>
  
  <p>What am I missing?</p>