new guy here. I'm trying to send an email through java, the following code that I am using is from this site;
public class NewClass extends Object{
public static void main(String [] args)
{
try{
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.mail.yahoo.com"); // for gmail use smtp.gmail.com
    props.put("mail.smtp.auth", "true");
    props.put("mail.debug", "true"); 
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.port", "587");
    props.put("mail.smtp.socketFactory.port", "587");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", "false");
    Session mailSession = Session.getInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("abcd@yahoo.com", "abcd");
        }
    });
    mailSession.setDebug(true); // Enable the debug mode
    Message msg = new MimeMessage( mailSession );
    //--[ Set the FROM, TO, DATE and SUBJECT fields
    msg.setFrom( new InternetAddress( "abcd@yahoo.com" ) );
    msg.setRecipients( Message.RecipientType.TO,InternetAddress.parse("efgh@gmail.com") );
    msg.setSentDate( new Date());
    msg.setSubject( "Hello World!" );
    //--[ Create the body of the mail
    msg.setText( "Hello from my first e-mail sent with JavaMail" );
    //--[ Ask the Transport class to send our mail message
    Transport.send( msg );
}catch(Exception E){
    System.out.println("Unable to send Mail");
    System.out.println( E );
}
} }
This is the Error I am Getting:
javax.mail.MessagingException: Could not connect to SMTP host: smtp.mail.yahoo.com, port: 587;  nested exception is: java.net.SocketException: Connection reset
What am I doing wrong here ? any help would be appreciated, TIA ! PS. sorry for any format errors.
 
    