Попробуйте этот код:
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.prot", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("PUT THE MAIL SENDER HERE !", "PUT THE PASSWORD OF THE MAIL SENDER HERE !");
}
}
);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("PUT THE MAIL SENDER HERE !"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("PUT THE MAIL RECEIVER HERE !"));
message.setSubject("MAIL SUBJECT !");
message.setText("MAIL BODY !");
Transport.send(message);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
Вам нужно меньше защищать безопасность отправителя почты. если проблема сохраняется, я думаю, что это может быть вызвано антивирусом, попробуйте отключить его.