title: Java SSL email error
body: <p>I was going through this <a href="http://www.bhaveshthaker.com/35/sending-mail-with-attachment-over-secure-socket-layer-ssl-through-smtp-using-javamail/" rel="nofollow noreferrer">Link</a> and tried to execute the code.</p>
  
  <p>Summary of the same is as follows:</p>
  
  <pre><code>    private static final String SSL_FACTORY = "SendMailDemoSSLSocketFactory"; //SendMailDemoSSLSocketFactory extends SSLSocketFactory       
  
      Properties props = new Properties();
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.submitter", emailUsername);
      props.put("mail.smtp.user", emailUsername);
      props.put("mail.smtp.host", smtpHostName);
      props.put("mail.debug", debug);
      props.put("mail.smtp.port", smtpPort);
      props.put("mail.smtp.ssl.socketFactory.port", smtpPort);
      props.put("mail.smtp.ssl.socketFactory.class", SSL_FACTORY);
      props.put("mail.smtp.socketFactory.fallback", "true");
      props.put("mail.smtp.ssl.enable", "true");
      props.put("mail.smtp.starttls.enable", "true");
      props.setProperty("mail.smtps.ssl.enable", "true");
      props.put("mail.transport.protocol", "smtps");
      props.put("mail.smtp.ssl.trust", smtpHostName);
  
      Session session = Session.getDefaultInstance(props,
              new javax.mail.Authenticator() {
                  protected PasswordAuthentication getPasswordAuthentication() {
                      return new PasswordAuthentication(emailUsername,
                              emailPassword);
                  }
              });
  
      session.setDebug(Boolean.parseBoolean(debug));
  
      Message msg = new MimeMessage(session);
      //set message
      SMTPSSLTransport transport = (SMTPSSLTransport) session
              .getTransport("smtps");
      transport.connect(smtpHostName, new Integer(smtpPort).intValue(),
              emailUsername, emailPassword);
      msg.saveChanges();
  
      transport.sendMessage(msg, msg.getAllRecipients());
  </code></pre>
  
  <p>With the same I was able to estb successful connection but authentication was unsuccessful. I am not able to find where is the code going wrong.</p>
  
  <pre><code>DEBUG: JavaMail version 1.4ea
  DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.7.0_25\jre\lib\javamail.providers (The system cannot find the file specified)
  DEBUG: !anyLoaded
  DEBUG: not loading resource: /META-INF/javamail.providers
  DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
  DEBUG: Tables of loaded providers
  DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
  DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
  DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
  DEBUG: !anyLoaded
  DEBUG: not loading resource: /META-INF/javamail.address.map
  DEBUG: successfully loaded file: C:\Program Files\Java\jdk1.7.0_25\jre\lib\javamail.address.map
  DEBUG: setDebug: JavaMail version 1.4ea 
  DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc]
  DEBUG SMTP: useEhlo true, useAuth false
  DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL true
  220 smtp.gmail.com ESMTP xv9sm19052844pbc.2 - gsmtp
  DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
  
  EHLO test
  250-smtp.gmail.com at your service, [182.64.100.170]
  250-SIZE 35882577
  250-8BITMIME
  250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH
  250-ENHANCEDSTATUSCODES
  250-PIPELINING
  250-CHUNKING
  250 SMTPUTF8
  DEBUG SMTP: Found extension "SIZE", arg "35882577"
  DEBUG SMTP: Found extension "8BITMIME", arg ""
  DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN XOAUTH"
  DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
  DEBUG SMTP: Found extension "PIPELINING", arg ""
  DEBUG SMTP: Found extension "CHUNKING", arg ""
  DEBUG SMTP: Found extension "SMTPUTF8", arg ""
  DEBUG SMTP: use8bit false
  </code></pre>
  
  <p>MAIL FROM:
      530-5.5.1 Authentication Required. Learn more at
      530 5.5.1  <a href="https://support.google.com/mail/answer/14257" rel="nofollow noreferrer">https://support.google.com/mail/answer/14257</a> xv9sm19052844pbc.2 - gsmtp
  com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required.             Learn more at   530 5.5.1 <a href="https://support.google.com/mail/answer/14257" rel="nofollow noreferrer">https://support.google.com/mail/answer/14257</a> xv9sm19052844pbc.2 - gsmtp</p>
  
  <pre><code>at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
  at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
  at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
  at edu.bhavesh.mail.smtp.ssl.SendMailDemo.sendSSLMessage(SendMailDemo.java:135)
  at edu.bhavesh.mail.smtp.ssl.SendMailDemo.main(SendMailDemo.java:41)
  </code></pre>
  
  <p>com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required. Learn more at
      530 5.5.1  <a href="https://support.google.com/mail/answer/14257" rel="nofollow noreferrer">https://support.google.com/mail/answer/14257</a> xv9sm19052844pbc.2 - gsmtp
      QUIT</p>
  
  <pre><code>at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
  at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
  at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
  at edu.bhavesh.mail.smtp.ssl.SendMailDemo.sendSSLMessage(SendMailDemo.java:135)
  at edu.bhavesh.mail.smtp.ssl.SendMailDemo.main(SendMailDemo.java:41)
  
      221 2.0.0 closing connection xv9sm19052844pbc.2 - gsmtp
  </code></pre>