title: Sending email in Java using Apache Commons email libs
body: <p>I am using Apache Commons Email library to send emails, but I am not able to send them via GMail SMTP server.<br>
  Can anyone provide sample code which works with GMail SMTP server and others?</p>
  
  <p>I am using the following code which does not work:</p>
  
  <pre><code>String[] recipients = {"receiver@gmail.com"};
  
  SimpleEmail email = new SimpleEmail();
  email.setHostName("smtp.gmail.com");
  email.setAuthentication("sender@gmail.com", "mypasswd");
  email.setDebug(true);
  email.setSmtpPort(465);
  
  for (int i = 0; i &lt; recipients.length; i++)
  {
      email.addTo(recipients[i]);
  }
  
  email.setFrom("sender@gmail.com", "Me");
  email.setSubject("Test message");
  email.setMsg("This is a simple test of commons-email");
  email.send();
  </code></pre>