title: Java email - Exception Server is not trusted
body: <p>I'm using apache commons mail to send emails. Unfortunately I'm getting following Exception:</p>
  
  <pre><code>org.apache.commons.mail.EmailException: Sending the email to the following server failed : mail.xxx.com:25
      at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
      at org.apache.commons.mail.Email.send(Email.java:1267)
      at com.xxx.UserBean.sendMail(UserBean.java:92)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  .
  .
  .
  Caused by: javax.mail.MessagingException: Could not convert socket to TLS;
    nested exception is:
      java.io.IOException: Server is not trusted: mail.xxx.com
      at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1880)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:648)
      at javax.mail.Service.connect(Service.java:317)
      at javax.mail.Service.connect(Service.java:176)
      at javax.mail.Service.connect(Service.java:125)
      at javax.mail.Transport.send0(Transport.java:194)
      at javax.mail.Transport.send(Transport.java:124)
      at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
      ... 85 more
  Caused by: java.io.IOException: Server is not trusted: mail.xxx.com
      at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:443)
      at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1875)
      ... 92 more
  </code></pre>
  
  <p>And here is my java code:</p>
  
  <pre><code>    public void sendMail(){
      try {  
          SimpleEmail mail = new SimpleEmail();
          mail.setTLS(true); 
          mail.setAuthenticator(new DefaultAuthenticator("user","xyxyxyxy"));
          mail.setHostName("mail.xxx.com");            
          mail.getMailSession().getProperties().put("mail.smtps.auth", true);
          mail.getMailSession().getProperties().put("mail.debug", true);
          mail.getMailSession().getProperties().put("mail.smtps.port", "587");
          mail.getMailSession().getProperties().put("mail.smtp.starttls.enable", true);
          mail.getMailSession().getProperties().put("mail.smtp.ssl.trust", "smtpserver");
  
          mail.addTo("user@server.com", "user");
          mail.setFrom("info@xxx.com");
          mail.setSubject("Bla Bla");
          mail.setMsg("Bla Bla again");
          mail.send();
                  } catch (Exception ex) {   
          logger.info("Senden der Email ist gescheitert!", ex);            
      }
   }
  </code></pre>
  
  <p>I've already read many threads and tried many hints. I'm stuck here!
  I should mention that I'm able to send emails with another method using "javax.mail". But I'd like to move to apache.</p>
  
  <p>I'm thankful for any help.</p>