Just a thought: on the same machine, try to connect to GMail using whatever email client is handy using the same settings. If this succeeds, then I would think the next step would be to deduce what is different between the settings in your code and the settings in the client.
When I get home maybe I will have time to try to hook up to GMail with JavaMail, but I do it a little differently. I use Velocity and templates because I send out merged mail, so I use the following from the Velocity/Spring examples:
Code:
protected MimeMessagePreparator prepareMessage (final String emailBody,
final String toAddress, final String fromAddress) throws MessagingException
{
MimeMessagePreparator preparator = new MimeMessagePreparator()
{
public void prepare (final MimeMessage mimeMessage)
throws MessagingException
{
MimeMessageHelper messageHelper = new MimeMessageHelper(
mimeMessage);
messageHelper.setTo(toAddress);
messageHelper.setFrom(fromAddress);
messageHelper.setSubject(_subject);
messageHelper.setText(emailBody, true);
}
};
return preparator;
}
and
Code:
_mailSender.send(prepareMessage(body, toAddress, fromAddress ));
where _mailSender is a JavaMailSender configured for an internal SMTP server.
Hope this helps.