Try this snippet changing your SMTP server.
Yahoo:
Outgoing Mail Server (SMTP): plus.smtp.mail.yahoo.com
Use SSL, port: 465, use authentication.
Snippet:
Properties props = new Properties();
props.put("mail.smtp.user", myEmail);
props.put("mail.smtp.host", smptServer);
props.put("mail.smtp.port", port);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.port", port);
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
try {
Authenticator auth = new autentificadorSMTP();
Session session = Session.getInstance(props, auth);
// session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setText(body);
msg.setSubject(subject);
msg.setFrom(new InternetAddress(myEmail));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
toEmail));
Transport.send(msg);
} catch (Exception mex) {
mex.printStackTrace();
}
Util:
private class authSMTP extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(myEmail, myPass);
}
}
Hope it helps!