title: How to correct Invalid Protocol: null sending mail using javax.mail
body: <p>i'm trying to send mail in this way:</p>
  
  <pre><code>Properties props = new Properties();
  props.setProperty("mail.transport.protocol", "smtp");
  props.setProperty("mail.host", "out.alice.it");
  props.setProperty("mail.user", "mymail@domain.it");
  props.setProperty("mail.password", "*****");
  Session mailSession = Session.getDefaultInstance(props, null);
  Transport transport = mailSession.getTransport();
  MimeMessage message = new MimeMessage(mailSession);
  message.setFrom(new InternetAddress("Host", "Name"));
  </code></pre>
  
  <p>On the row <code>Transport transport...</code> i retrieve this error:</p>
  
  <pre><code>javax.mail.NoSuchProviderException: Invalid protocol: null
      at javax.mail.Session.getProvider(Session.java:440)
      at javax.mail.Session.getTransport(Session.java:659)
      at javax.mail.Session.getTransport(Session.java:640)
      at javax.mail.Session.getTransport(Session.java:626)
      at Mail.sendMail(Mail.java:151)
  </code></pre>
  
  <p>How can i resolve? Can someone help me? Thanks!! :)</p>
  
  <p>EDIT:</p>
  
  <p>If i create a main and launch that method to send mail, it works good!
  My problem borns after i read mail into mail folder:</p>
  
  <pre><code>Properties properties = System.getProperties();  
  properties.setProperty("mail.store.protocol", "imap");  
  Session session = Session.getDefaultInstance(properties, null);
  Store store = session.getStore("pop3");
  store.connect("pop3.domain.it", "mail@domain.it", "****");  
  Folder inbox = store.getFolder("inbox");  
  FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
  inbox.open(Folder.READ_ONLY);
  Message messages[] = inbox.search(ft);
  for(Message message:messages) {
     if(message.getFrom()[0].toString().equals("aMail")){
        sendMail(message.getFrom()[0].toString());//Error!
     }
  }
  </code></pre>
  
  <p>I Thought the exception borns cause i've opened store to get inbox mail so i edit in this way:</p>
  
  <pre><code>ArrayList&lt;String&gt; reply = new ArrayList&lt;String();
  for(Message message:messages) {
      if(message.getFrom()[0].toString().equals("aMail")){
          reply.add(message.getFrom()[0].toString());
      }
  }
  store.close();
  for(String mail : reply){
     sendMail(mail); // ERROR AGAIN!
  }
  </code></pre>
  
  <p>very strange....</p>
  
  <p>SOLVED IN THIS WAY:</p>
  
  <p>i modified this row</p>
  
  <pre><code>Session mailSession = Session.getDefaultInstance(props, null);
  </code></pre>
  
  <p>to </p>
  
  <pre><code>Session mailSession = Session.getInstance(props);
  </code></pre>