(Summary could be worded better)
If you define MailSession in components.xml like this:
<mail:mail-session host="@mailhost@" port="@mailport@" username="@mailusername@" password="@mailpassword@" />
And set the mailusername and mailpassword in the environment specific components.properties files, you can't use a mail server without authentication in any environment.
Putting this in a components.properties:
seems to set an empty string into the property, which passes the "(getUsername() != null" test in MailSession.java used to determine if it should authenticate with the mail server.
Therefore it tries to authenticate with empty username and password, which typically fails on a system that doesn't not require auth for outgoing mail (from internal servers for instance).
In this scenario our dev environment needs to use a mail server that does require auth, but in production, it needs to use a mail server without auth. Currently this is requiring us to manually change the components.xml to have:
<mail:mail-session host="@mailhost@" port="@mailport@" />
in the production ear.
A simple fix would be to change the logic in MailSession to do:
getUsername() != null && getUsername().trim().length() > 0 instead of the current null check.
The relevant lines to change are 105, 109, and 152.