This program attempts to send e-mail but throws a run time exception:
javax.mail.AuthenticationFailedException: failed to connect, no password specified?
Even when using an Authenticator I had to set mail.smtp.auth property to true. Here is a working example:
final Properties props = new Properties();
props.put("mail.smtp.host", config.getSmtpHost());
props.setProperty("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(config.getSmtpUser(), config.getSmtpPassword());
}
});