title: Why connection is timed out in Javamail?
body: <p>I'm trying to use javamail in eclipse to send out an email via gmail. Each time I get javax.mail.MessagingException</p>
  
  <p><strong>Exception</strong></p>
  
  <pre><code> DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
      DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
      DEBUG SMTP: useEhlo true, useAuth true
      DEBUG SMTP: useEhlo true, useAuth true
      DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
      javax.mail.MessagingException: Could not connect to SMTP host: 
  
  smtp.gmail.com, port: 587;
    nested exception is:
      java.net.ConnectException: Connection timed out: connect
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code>package org.itc.utility;
  
  import java.util.Properties;
  
  import javax.mail.Message;
  import javax.mail.PasswordAuthentication;
  import javax.mail.Session;
  import javax.mail.Transport;
  import javax.mail.internet.InternetAddress;
  import javax.mail.internet.MimeMessage;
  
  import org.itc.model.User;
  
  public class SendEmail {
      public User sendingEmail(User user)
      {
          Properties props = new Properties();  
          props.put("mail.smtp.host", "smtp.gmail.com");  
          props.put("mail.smtp.auth", "true");  
          props.put("mail.debug", "true");  
          props.put("mail.smtp.port", 587);  
          props.put("mail.smtp.socketFactory.port", 587);  
          props.put("mail.smtp.starttls.enable", "true");
          props.put("mail.transport.protocol", "smtp");
          Session mailSession = null;
  
          mailSession = Session.getInstance(props,  
                  new javax.mail.Authenticator() {  
              protected PasswordAuthentication getPasswordAuthentication() {  
                  return new PasswordAuthentication("&lt;yogeshvbhat@gmail.com&gt;", "&lt;zc516z918&gt;");  
              }  
          });  
  
  
          try {
  
  
              Transport transport = mailSession.getTransport();
  
              MimeMessage message = new MimeMessage(mailSession);
  
              message.setSubject("Sample Subject");
              message.setFrom(new InternetAddress("yogeshvbhat@gmail.com"));
              String []to = new String[]{"yogeshyvb@gmail.com"};
              message.addRecipient(Message.RecipientType.TO, new InternetAddress(to[0]));
              String body = "Sample text";
              message.setContent(body,"text/html");
              transport.connect();
  
              transport.sendMessage(message,message.getRecipients(Message.RecipientType.TO));
              transport.close();
          } catch (Exception exception) {
                  System.out.println(exception);
          }
          return user;
      }
  }
  </code></pre>
  
  <p>Each time it is skipping the try block and I'm getting the exception. Any help on this?</p>