Sender's name is not taken into account by WildFly while sending mails
<p>Mail service configuration in standalone-full-ha.xml.</p>

<pre class="lang-xml prettyprint-override"><code>&lt;mail-session name="default" jndi-name="java:jboss/mail/Default" from="admin@mydomain.com"&gt;
    &lt;smtp-server outbound-socket-binding-ref="mail-smtp"
                 ssl="true"
                 username="sender@gmail.com"
                 password="password"/&gt;
&lt;/mail-session&gt;
</code></pre>

<pre class="lang-xml prettyprint-override"><code>&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>Injecting the mail session through the service bound to the JNDI name <code>java:jboss/mail/Default</code> and sending mails using that mail session.</p>

<pre><code>@Resource(lookup = "java:jboss/mail/Default")
private Session mailSession; // javax.mail.Session

MimeMessage mimeMessage = new MimeMessage(mailSession);
Address[] to = new InternetAddress[]{new InternetAddress("recipient@gmail.com")};

mimeMessage.setRecipients(javax.mail.Message.RecipientType.TO, to);
mimeMessage.setSubject("Subject", "UTF-8");
mimeMessage.setSentDate(new Date());
mimeMessage.setText("Message", "UTF-8", "html");
Transport.send(mimeMessage);
</code></pre>

<p>Now, the sender's name i.e <code>from="admin@mydomain.com"</code> as specified in the XML configuration above is expected to be sent as a sender but the server instead keeps on sending the user name as specified by <code>username="sender@gmail.com"</code> as a sender.</p>

<p>Doing like the following in Java code itself does not help either which works in Java SE environment.</p>

<pre><code>Address from = new InternetAddress("admin@mydomain.com");
mimeMessage.setFrom(from);
</code></pre>

<p>What consequences the server dislikes.</p>

<p><sub>Using WildFly 9.0.2 final.</sub></p>

<hr>

<p><strong>Update :</strong></p>

<p>The debug output on the server log.</p>

<pre><code>06:27:24,562 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
06:27:24,562 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: useEhlo true, useAuth true
06:27:24,562 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
06:27:25,296 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 220 smtp.gmail.com ESMTP g26sm26113121pfg.35 - gsmtp
06:27:25,296 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
06:27:25,296 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 
06:27:25,296 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) EHLO om-f6b0ea3ad206
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250-smtp.gmail.com at your service, [117.198.186.188]
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250-SIZE 35882577
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250-8BITMIME
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250-ENHANCEDSTATUSCODES
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250-PIPELINING
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250-CHUNKING
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250 SMTPUTF8
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: Found extension "SIZE", arg "35882577"
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: Found extension "8BITMIME", arg ""
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: Found extension "PIPELINING", arg ""
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: Found extension "CHUNKING", arg ""
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: Found extension "SMTPUTF8", arg ""
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
06:27:25,625 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: AUTH LOGIN command trace suppressed
06:27:26,578 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: AUTH LOGIN succeeded
06:27:26,578 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: use8bit false
06:27:26,578 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) MAIL FROM:&lt;sender@gmail.com&gt;
06:27:26,875 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250 2.1.0 OK g26sm26113121pfg.35 - gsmtp
06:27:26,875 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) RCPT TO:&lt;recipient@gmail.com&gt;
06:27:27,156 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250 2.1.5 OK g26sm26113121pfg.35 - gsmtp
06:27:27,156 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: Verified Addresses
06:27:27,156 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP:   recipient@gmail.com
06:27:27,156 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DATA
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 354  Go ahead g26sm26113121pfg.35 - gsmtp
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) Date: Sat, 30 Jan 2016 06:27:24 +0530 (IST)
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) To: recipient@gmail.com
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) Message-ID: &lt;17076900.1.1454115444562@gmail.com&gt;
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) Subject: Subject
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) MIME-Version: 1.0
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) Content-Type: text/html; charset=UTF-8
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) Content-Transfer-Encoding: 7bit
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) Message
06:27:27,515 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) .
06:27:28,437 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 250 2.0.0 OK 1454114106 g26sm26113121pfg.35 - gsmtp
06:27:28,437 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG SMTP: message successfully delivered to mail server
06:27:28,437 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) QUIT
06:27:28,718 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) 221 2.0.0 closing connection g26sm26113121pfg.35 - gsmtp
06:27:28,718 INFO  [stdout] (Thread-21 (HornetQ-client-global-threads-7949294)) DEBUG: setDebug: JavaMail version 1.5.3
</code></pre>

<hr>

<p>Sending a mail using a Java SE console application :</p>

<pre><code>public class Mail {

    public static void main(String[] args) throws MessagingException, UnsupportedEncodingException {
        send("sender@gmail.com", "password", "recipient@gmail.com", "Subject", "Message", "Sender Name");
    }

    private static void send(String sender, String password, String recipient, String subject, String message, String senderName) throws MessagingException, UnsupportedEncodingException {
        Properties props = System.getProperties();
        props.setProperty("mail.smtps.host", "smtp.gmail.com");
        props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.setProperty("mail.smtp.socketFactory.fallback", "false");
        props.setProperty("mail.smtp.port", "465");
        props.setProperty("mail.smtp.socketFactory.port", "465");
        props.setProperty("mail.smtps.auth", "true");
        props.setProperty("mail.debug", "true");
        props.put("mail.smtps.quitwait", "false");

        Session session = Session.getInstance(props, null);
        final MimeMessage mimeMessage = new MimeMessage(session);

        mimeMessage.setFrom(new InternetAddress(sender, senderName, "UTF-8"));
        mimeMessage.setRecipients(Message.RecipientType.TO, new InternetAddress[]{new InternetAddress(recipient)});
        mimeMessage.setSubject(subject, "UTF-8");
        mimeMessage.setText(message, "UTF-8", "html");
        mimeMessage.setSentDate(new Date());

        Transport transport = session.getTransport("smtps");
        transport.connect("smtp.gmail.com", sender, password);
        transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
        transport.close();
    }
}
</code></pre>

<p>It can take any arbitrary name as the sender name as specified in the last parameter of the <code>send()</code> method above.</p>

<p>On opening the message sent, the sender is shown like <code>Sender Name &lt;sender@gmail.com&gt;</code> in the message body. In the former case, it is however shown like <code>sender@gmail.com</code>.</p>

<p>The debug output on the console terminal device :</p>

<pre><code>DEBUG: JavaMail version 1.5.5
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,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
220 smtp.gmail.com ESMTP m87sm26277196pfi.47 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465

EHLO om-f6b0ea3ad206
250-smtp.gmail.com at your service, [117.198.186.188]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2 
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:&lt;sender@gmail.com&gt;
250 2.1.0 OK m87sm26277196pfi.47 - gsmtp
RCPT TO:&lt;recipient@gmail.com&gt;
250 2.1.5 OK m87sm26277196pfi.47 - gsmtp
DEBUG SMTP: Verified Addresses
DEBUG SMTP:   recipient@gmail.com
DATA
354  Go ahead m87sm26277196pfi.47 - gsmtp
Date: Sat, 30 Jan 2016 07:46:18 +0530 (IST)
From: Sender Name &lt;sender@gmail.com&gt;
To: recipient@gmail.com
Message-ID: &lt;13329486.0.1454120181750@om-f6b0ea3ad206&gt;
Subject: Subject
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

Message
.
250 2.0.0 OK 1454118752 m87sm26277196pfi.47 - gsmtp
DEBUG SMTP: message successfully delivered to mail server
QUIT
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
</code></pre>

<p>The sender's password used is an application specific password obtained during "2-Step Verification" at <code>https://security.google.com/settings/security/apppasswords</code>.</p>

<p><sub>The difference in versions of the API is negligible / can safely be ignored in this case. I already attempted using older versions of the java-mail API. The former uses the version 1.5.3 and the latter uses the version 1.5.5.</sub></p>