title: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
body: <p>I have a Maven project, use JSF 2.2, Tomcat 7 and use <code>Apache Commons</code> for sending e-mail.</p>
  
  <p>Here is my code</p>
  
  <pre><code>try {
      // Create the email message
      HtmlEmail email = new HtmlEmail();
      email.setSmtpPort(465); //email.setSslSmtpPort("465");
      email.setSSLOnConnect(true);
      email.setHostName("smtp.gmail.com");
      email.addTo("test@gmail.com", "test");
      email.setFrom(getEmail(), getName());
      email.setSubject(getSubject());
      email.setHtmlMsg("&lt;html&gt;Test&lt;/html&gt;"); // set the html message
      email.setTextMsg(getText());// set the alternative message
      email.send();// send the email
  } catch (EmailException e) {
      logger.error("Exception sending email: ", e);
  } catch (Exception ex) {
      logger.error("Exception sending email: ", ex);
  }
  </code></pre>
  
  <p>When I tried to run the code in Tomcat 7, I got the following exception:</p>
  
  <blockquote>
    <p>org.apache.commons.mail.EmailException: Sending the email to the
    following server failed : smtp.gmail.com:465</p>
  </blockquote>