In Java EE you can use the @MailSessionDefinition annotation (or its equivalent in XML) to define the mail Session that you later on inject.
Its user
and password
attributes are the declarative version of the programmatic Authenticator's PasswordAuthentication.
@MailSessionDefinition
is available on Java EE 7 servers, such as GlassFish 4 and also already in WildFly 8 (previously JBoss AS 8).