title: javamail using "normal" provider
body: <p>Maybe it's trivial... but for me is becoming a huge waste of time because I'm not able to find the solution.</p>
  
  <p>this is my code (I extrapolated first lines from very common examples on internet):</p>
  
  <pre><code>static Properties properties = new Properties();
  {
      properties.put("mail.smtp.host", getText("smtp.host"));
      properties.put("mail.smtp.socketFactory.port", getText("socketFactory.port"));
      properties.put("mail.smtp.socketFactory.class", getText("socketFactory.class"));
      properties.put("mail.smtp.auth", getText("smtp.auth"));
      properties.put("mail.smtp.port", getText("smtp.port"));
  
      properties.put("mail.smtp.starttls.enable", "true");
  }
  
  private String from = getText("from");
  private String smtppw = getText("pw");
  
  private void initMS() {
      if (smtppw != null) {
          mailsession = Session.getDefaultInstance(properties,  new Authenticator() {
  
              protected PasswordAuthentication  getPasswordAuthentication() {
                  return new PasswordAuthentication(from, smtppw);
              }
          });
      }
      else {
          mailsession = Session.getDefaultInstance(properties,  new Authenticator() {
              protected PasswordAuthentication  getPasswordAuthentication() {
                  return new PasswordAuthentication(from, null);
              }
          });
      }   
  }
  
  
  
  String attachpath =  ServletActionContext.getServletContext().getRealPath("/");
  
  public String sendNote(String type, SendingParamsDTO sendingParams, String filename) throws /*AddressException,*/ MessagingException {
  
      String res = SUCCESS;
      //try {
  
          if (mailsession == null) initMS();
  
          Message message = new MimeMessage(mailsession);
  
          InternetAddress pobox = new InternetAddress(from);
          InternetAddress to[] = InternetAddress.parse(sendingParams.getMailto());
  
          message.setFrom(pobox);
          message.setRecipients( Message.RecipientType.TO, to);
          message.addHeader("Disposition-Notification-To", from);
          message.setSubject("[AN-V.C.O.] - "+sendingParams.getSubject() );
          message.setSentDate( sendingParams.getDate() );
  
          /**/
          logger.info(" ##  FROM: "+from);
          logger.info(" ##  TO:  "+to);
          logger.info(" ##  SUBJECT:     "+sendingParams.getSubject());
          logger.info(" ##  MESSAGE:   "+sendingParams.getMessage());
          if (filename != null)
              logger.info(" ##  ATTACH:    "+attachpath + filename);
          /**/
  
  
          MimeMultipart multipart = new MimeMultipart("related");
          //Multipart multipart = new MimeMultipart();
  
          BodyPart messageBodyPart1 = new MimeBodyPart();
  
          if (type.equals("text"))
              messageBodyPart1.setText(sendingParams.getMessage());
          else if (type.equals("html"))
              messageBodyPart1.setContent(sendingParams.getMessage(), "text/html");
  
  
          BodyPart messageBodyPart2 = null;
          if (filename != null){
              DataSource source = new FileDataSource(attachpath);
              messageBodyPart2 = new MimeBodyPart();
              messageBodyPart2.setDataHandler( new DataHandler(source) );
              messageBodyPart2.setFileName( filename );
          }
  
  
          multipart.addBodyPart( messageBodyPart1 );
          if (filename != null){
              multipart.addBodyPart( messageBodyPart2 );
          }
  
  
          message.setContent(multipart);
  
  
          Transport.send(message, message.getRecipients(Message.RecipientType.TO));
          //Transport transport = mailsession.getTransport();
          //transport.connect();
          //transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
          //transport.close();
  
      //}
      //catch(Exception e) {
      //  res = ERROR;
      //  e.printStackTrace();
      //}
  
      return res;
  }
  </code></pre>
  
  <p>where</p>
  
  <pre><code>## generic using GMAIL
  smtp.host=smtp.gmail.com
  socketFactory.port=465
  socketFactory.class=javax.net.ssl.SSLSocketFactory
  smtp.auth=true
  smtp.port=465
  </code></pre>
  
  <p>and so all works fine!
  Now I need to change gmail whit a commercial provider. I transformed my code in this way:</p>
  
  <p>properties file becomes</p>
  
  <pre><code>## real using myprovider
  smtp.host=smtp.myprovider.com
  #socketFactory.port=465
  #socketFactory.class=javax.net.ssl.SSLSocketFactory
  smtp.auth=true
  smtp.port=465
  </code></pre>
  
  <p>and java code</p>
  
  <pre><code>static Properties properties = new Properties();
  {
      properties.put("mail.smtp.host", getText("smtp.host"));
      //properties.put("mail.smtp.socketFactory.port", getText("socketFactory.port"));
      //properties.put("mail.smtp.socketFactory.class", getText("socketFactory.class"));
      properties.put("mail.smtp.auth", getText("smtp.auth"));
      properties.put("mail.smtp.port", getText("smtp.port"));
  
      //properties.put("mail.smtp.starttls.enable", "true");
  }
  </code></pre>
  
  <p>I tried also to keep socketfactory, to use my personal mail provider so avoiding to specify authentication and port... but still doesn't works!<br>
  what's wrong?
  Thanx</p>
  
  <p>PS-more specific. No error or exception is returned, only the process remains hanging executing line  </p>
  
  <pre><code>Transport.send(message, message.getRecipients(Message.RecipientType.TO));
  </code></pre>