Try to create an javax.mail.Authenticator Object, and send that in with the properties object to the Session object.
Authenticator edit:
You can modify this to accept a username and password and you can store them there, or where ever you want.
public class SmtpAuthenticator extends Authenticator {
public SmtpAuthenticator() {
super();
}
@Override
public PasswordAuthentication getPasswordAuthentication() {
String username = "user";
String password = "password";
if ((username != null) && (username.length() > 0) && (password != null)
&& (password.length () > 0)) {
return new PasswordAuthentication(username, password);
}
return null;
}
In your class where you send the email:
SmtpAuthenticator authentication = new SmtpAuthenticator();
javax.mail.Message msg = new MimeMessage(Session
.getDefaultInstance(emailProperties, authenticator));