title: JavaMail API Error (javax.mail.NoSuchProviderException: invalid provider)
body: <p>I'm trying to create a program using the JavaMail API, however, I keep getting the following error message.</p>
  
  <pre><code>javax.mail.NoSuchProviderException: invalid provider
  at javax.mail.Session.getTransport(Session.java:738)
  at javax.mail.Session.getTransport(Session.java:682)
  at javax.mail.Session.getTransport(Session.java:662)
  at EmailAutoResponder2.main(EmailAutoResponder2.java:56)
  </code></pre>
  
  <p>I was not able to solve it by reading online, as all of their solutions still gave me the same message.</p>
  
  <p>Here is the Java code:</p>
  
  <pre><code>import java.util.*;
  import javax.mail.*;
  import javax.mail.internet.*;
  
  public class EmailAutoResponder2 {
  
  public static void main(String[] args) {
  
      String to = "username@videotron.ca";
      String from = "username@videotron.ca";
  
      Properties properties = System.getProperties();
  
      properties.setProperty("mail.store.protocol", "imaps");
  
      Session session1 = Session.getInstance(properties);
  
      //If email received by specific user, send particular response.
      Properties props = new Properties();
  
      props.put("mail.imap.auth", "true");
      props.put("mail.imap.starttls.enable", "true");
      props.put("mail.imap.host", "imap.videotron.ca");
      props.put("mail.imap.port", "143");
  
      Session session2 = Session.getInstance(props, new Authenticator() {
  
                  protected PasswordAuthentication getPasswordAuthentication() {
                          return new PasswordAuthentication("username@videotron.ca", "password");
              }
          });
  
      try {
          Store store = session2.getStore("imap");
          store.connect("imap.videotron.ca", "username@videotron.ca", "password");
          Folder fldr = store.getFolder("Inbox");
          fldr.open(Folder.READ_ONLY);
          Message msgs[] = fldr.getMessages(); 
              for(int i = 0; i &lt; msgs.length; i++){
                  System.out.println(InternetAddress.toString(msgs[i].getFrom()));
  
              if (InternetAddress.toString(msgs[i].getFrom()).startsWith("Name")){
  
                  MimeMessage message = new MimeMessage(session1);
  
                  message.setFrom(new InternetAddress(from));
                  message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
                  message.setSubject("Subject");
                  message.setText("Message");
  
                  String protocol = "imap";
                  props.put("mail." + protocol + ".auth", "true");
  
                  Transport t = session2.getTransport("imap");
                  try {
                      t.connect("username@videotron.ca", "password");
                      t.sendMessage(message, message.getAllRecipients());
                  }
                  finally {
                      t.close();
                  }
  
              }
              }
  
      }
  
      catch(MessagingException mex){
          mex.printStackTrace();
      }
  
      catch(Exception exc) {
  
      }
  
      }
  
      }
  </code></pre>
  
  <p>Thank you!</p>