title: JavaMail cannot send email
body: <p>i am trying to write an application in java that will send emails, i found a tutorial on youtube and tried to follow it. however it does not work for me still, here is the error i get</p>
  
  <pre><code>Exception in thread "main" javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25, response: 421
  at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1949)
  at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
  at javax.mail.Service.connect(Service.java:295)
  at javax.mail.Service.connect(Service.java:176)
  at javax.mail.Service.connect(Service.java:125)
  at javax.mail.Transport.send0(Transport.java:194)
  at javax.mail.Transport.send(Transport.java:124)
  at libraryFineList.ParseRecords.main(ParseRecords.java:90)
  </code></pre>
  
  <p>i have no idea, what's wrong, anything i found on google did not help, </p>
  
  <p>here is the code</p>
  
  <pre><code>    public static void main(String[] args) throws IOException, MessagingException {
  
      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("user@gmail.com", "pass");
  
          }
      }
  
              );
  
      try{
          Message message = new MimeMessage(session);
          message.setFrom(new InternetAddress("user@gmail.com"));
          message.addRecipient(Message.RecipientType.TO,
                     new InternetAddress("ycharnetskaya@gmail.com", "Mr. User"));
          message.setSubject("Your Example.com account has been activated");
          message.setText("Worked");
    Transport.send(message);
      }catch(Exception e){
          e.printStackTrace();
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/ilHyp.jpg" alt="here are the libraries that i downloaded and added to build path"></p>
  
  <p><img src="https://i.stack.imgur.com/Meo2H.jpg" alt="enter image description here"></p>