title: Sending emails over SMTP with TSL
body: <p>The code posted below works fine for me to send an email over an STMP with SSL. 
  Now the SMTP changed to TSL and i dont manage to send email with it. 
  I tried several things like adding</p>
  
  <pre><code>props.put("mail.smtp.starttls.enable","true");
  </code></pre>
  
  <p>but it was no use.</p>
  
  <p>The error code says: </p>
  
  <p>"javax.mail.MessagingException: Could not connect to SMTP host: exch.studi.fhws.de, port: 587;
    nested exception is:
      javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?"</p>
  
  <p>Any ideas?</p>
  
  <pre><code>import javax.mail.*;
  import javax.mail.internet.*;
  import java.util.*;
  
  public class SendMail
  {
  String d_email = "...",
  password = "...",
  host = "...",
  port = "25",
  mailTo = "...",
  mailSubject = "test",
  mailText = "test";
  
  public SendMail()
  {
      Properties props = new Properties();
      props.put("mail.smtp.user", d_email);
      props.put("mail.smtp.host", host);
      props.put("mail.smtp.port", port);
      props.put("mail.smtp.starttls.enable","true");
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.socketFactory.port", port);
      props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
      props.put("mail.smtp.socketFactory.fallback", "false");
  
      SecurityManager security = System.getSecurityManager();
  
      try
      {
          Authenticator auth = new SMTPAuthenticator();
          Session session = Session.getInstance(props, auth);
  
          MimeMessage msg = new MimeMessage(session);
          msg.setText(mailText);
          msg.setSubject(mailSubject);
          msg.setFrom(new InternetAddress(d_email));
          msg.addRecipient(Message.RecipientType.TO, new InternetAddress(mailTo));
          Transport.send(msg);
      }
      catch (Exception mex)
      {
          mex.printStackTrace();
      }
  }
  
  public static void main(String[] args)
  {
      TextClass tc = new TextClass();
  }
  
  private class SMTPAuthenticator extends javax.mail.Authenticator
  {
      public PasswordAuthentication getPasswordAuthentication()
      {
          return new PasswordAuthentication(d_email, password);
      }
  }
  }
  </code></pre>