Java SSL Email Error

I went through Link and tried to execute the code.

Summary of the same:

    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());

With the same success, I was able to verify a successful connection, but authentication was unsuccessful. I can not find where the code is wrong.

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

MAIL FROM: 530-5.5.1 Authentication required. Find out more at 530 5.5.1 https://support.google.com/mail/answer/14257 xv9sm19052844pbc.2 - gsmtp com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication is required. Read more at 530 5.5.1 https://support.google.com/mail/answer/14257 xv9sm19052844pbc.2 - gsmtp

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)

com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 .   530 5.5.1 https://support.google.com/mail/answer/14257 xv9sm19052844pbc.2 - gsmtp   QUIT

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
+4
1

, gmail smtp, : jars :

  • mail.jar
  • activation.jar
  • additionnal.jar
  • --2.4.jar

    String sendingHost = "smtp.gmail.com";
    int sendingPort =  465;
    Properties props = new Properties();
    props.put("mail.smtp.host", sendingHost);
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", sendingPort + "");
    /**ADD THIS**/
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.starttls.required", "true");
    
    props.put("mail.smtp.SSL", "true");
    props.put("mail.smtp.ehlo", "true");
    /**  **/
    
    Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
    protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(email.getFromAccount().getEmail(), email.getFromAccount().getPassword());
    }
    });
    
0

All Articles