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.port", "465");
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("aaaaaaaaaaa", "bbbbbbbbb");
}
});
session.setDebug(true);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("xxxxxxxxxx"));
Address[] toUser = InternetAddress.parse("zzzzzzzzzz");
message.setRecipients(Message.RecipientType.TO, toUser);
message.setSubject("Enviando email com JavaMail");
message.setText("Enviei este email utilizando JavaMail com a minha conta GMail!");
Transport.send(message);
System.out.println("Email enviado com sucesso!!!");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
Estou a usar este código para enviar email,será que alguém podia ajudar?Este código da o seguinte erro:
Error: Unable to initialize main class gui.JavaMailApp
Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException