title: Getting javax.mail.NoSuchProviderException when try to send mail using java
body: <p>I have read and tried all solution given in stackoverflow and in other various sites but still getting issue and getting exception.</p>
  
  <p>Code : </p>
  
  <pre><code>import java.util.Properties;
  
  import javax.mail.Message;
  import javax.mail.MessagingException;
  import javax.mail.Session;
  import javax.mail.Transport;
  import javax.mail.internet.AddressException;
  import javax.mail.internet.InternetAddress;
  import javax.mail.internet.MimeMessage;
  
  public class sendmail {
  
  Properties emailProperties;
  Session mailSession;
  MimeMessage emailMessage;
  
  public static void main(String args[]) throws AddressException,
          MessagingException {
  
      sendmail javaEmail = new sendmail();
  
      javaEmail.setMailServerProperties();
      javaEmail.createEmailMessage();
      javaEmail.sendEmail();
  }
  
  public void setMailServerProperties() {
  
      String emailPort = "587";//gmail's smtp port
  
      emailProperties = System.getProperties();
      emailProperties.put("mail.smtp.port", emailPort);
      emailProperties.put("mail.smtp.auth", "true");
      emailProperties.put("mail.smtp.starttls.enable", "true");
  
  }
  
  public void createEmailMessage() throws AddressException,
          MessagingException {
      String[] toEmails = { "emailid@gmail.com" };
      String emailSubject = "Java Email";
      String emailBody = "This is an email sent by JavaMail api.";
  
      mailSession = Session.getDefaultInstance(emailProperties, null);
      emailMessage = new MimeMessage(mailSession);
  
      for (int i = 0; i &lt; toEmails.length; i++) {
          emailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmails[i]));
      }
  
      emailMessage.setSubject(emailSubject);
      emailMessage.setContent(emailBody, "text/html");//for a html email
      //emailMessage.setText(emailBody);// for a text email
  
  }
  
  public void sendEmail() throws AddressException, MessagingException {
  
      String emailHost = "smtp.gmail.com";
      String fromUser = "emailid";//just the id alone without @gmail.com
      String fromUserEmailPassword = "test";
  
      Transport transport = mailSession.getTransport("smtp");
  
      transport.connect(emailHost, fromUser, fromUserEmailPassword);
      transport.sendMessage(emailMessage, emailMessage.getAllRecipients());
      transport.close();
      System.out.println("Email sent successfully.");
  }
  
   }
  </code></pre>
  
  <p>When I debug code , it stop working at line : <strong>Transport transport = mailSession.getTransport("smtp");</strong></p>
  
  <p>I have added following JARs :</p>
  
  <blockquote>
    <p>Mail.jar , pop3.jar , smtp-1.4.2.jar , Activation.jar , additional.jar</p>
  </blockquote>
  
  <p>Full exception :</p>
  
  <blockquote>
    <p>Exception in thread "main" javax.mail.NoSuchProviderException: smtp
        at javax.mail.Session.getService(Session.java:764)
        at javax.mail.Session.getTransport(Session.java:689)
        at javax.mail.Session.getTransport(Session.java:632)
        at javax.mail.Session.getTransport(Session.java:612)
        at javax.mail.Session.getTransport(Session.java:667)
        at javax.mail.Transport.send0(Transport.java:154)
        at javax.mail.Transport.send(Transport.java:80)
        at JannyaPaid_Device.sendmail.sendEmail(sendmail.java:68)
        at JannyaPaid_Device.sendmail.main(sendmail.java:26)</p>
  </blockquote>
  
  <p>Also I want to ask that firewall can prevent this things to send mail? As we have some firewall installed but I able to open and send mail thrugh gmail manually.</p>