title: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
body: <p>while sending mail I am getting this error</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: javax.mail.SendFailedException: Sending
    failed;   nested exception is:    class javax.mail.MessagingException:
    Could not connect to SMTP host: smtp.gmail.com, port: 465, response:
    -1</p>
  </blockquote>
  
  <p>my code is:</p>
  
  <pre><code>Properties props = new Properties();
  props.put("mail.smtp.host", "smtp.gmail.com");
  props.put("mail.smtp.starttls.enable","true");
  props.put("mail.smtp.socketFactory.port", "465");
  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("email","password");
                  }
          });
  
  try {
  
          Message message = new MimeMessage(session);
          message.setFrom(new InternetAddress("email"));
          message.setRecipients(Message.RecipientType.TO,
                          InternetAddress.parse(this.to));
          message.setSubject("Testing");
          message.setText("Hey, this is the testing email.");
  
  
  
          Transport.send(message);
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks in Advance.</p>