I ve got this exception after reformating my code:
javax.mail.NoSuchProviderException: No provider for earthlink.net
at javax.mail.Session.getProvider(Session.java:455)
at javax.mail.Session.getTransport(Session.java:650)
at javax.mail.Session.getTransport(Session.java:631)
at Reminder.sendMessage(Reminder.java:42)
at Reminder.main(Reminder.java:99)
Code:
try {
String smtp = "earthlink.net";
Properties props = System.getProperties();
props.put("mail.smtp.host", smtp);
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.setFrom( new InternetAddress("me@hotmail.com"));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress("emailadress@hotmail.com"));
message.setSubject("Subject");
message.setText("Body Text");
Transport t = session.getTransport(smtp);
try {
t.connect("username", "password");
t.sendMessage(message, message.getAllRecipients());
} catch (Exception e) { }
finally {
t.close();
}
} catch (Exception e){
e.printStackTrace();
}