title: Can not send email through gmail with Apache Commons Email.
body: <p>Can not send email through gmail with Apache Commons Email.What is the problem?</p>
  
  <pre><code>Email email = new SimpleEmail();
          email.setHostName("smtp.gmail.com");
          email.setSmtpPort(587);
          email.setTLS(true);
          email.setAuthenticator(new DefaultAuthenticator("mymail@gmail.com", "mypassword"));
          email.setFrom("mymail@gmail.com");
          email.setSubject("TestMail");
          email.setMsg("This is a test mail ... :-)");
          email.addTo("sendmail@gmail.com");
          email.send();
  </code></pre>
  
  <p>Error: </p>
  
  <pre><code>Exception in thread "main" org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:587
      at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
      at org.apache.commons.mail.Email.send(Email.java:1267)
      at MailService.sendSimpleMail(MailService.java:51)
      at MailService.main(MailService.java:17)
  Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
    nested exception is:
      java.net.ConnectException: Connection refused: connect
      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
      at javax.mail.Service.connect(Service.java:310)
      at javax.mail.Service.connect(Service.java:169)
      at javax.mail.Service.connect(Service.java:118)
      at javax.mail.Transport.send0(Transport.java:188)
      at javax.mail.Transport.send(Transport.java:118)
      at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
      ... 3 more
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
      at java.net.Socket.connect(Socket.java:519)
      at java.net.Socket.connect(Socket.java:469)
      at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
      at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
      ... 10 more
  </code></pre>