Error Caused by: javax.mail.Authenticationfailedexception

Asked

Viewed 123 times

0

I’m trying to use the Commons Email library, but this is giving the following error

Exception in thread "main" org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
  at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469)
  at org.apache.commons.mail.Email.send(Email.java:1496)
  at bibliotecaemail.UsandoBibliotecaDeEmail.main(UsandoBibliotecaDeEmail.java:21)
Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt
534-5.7.14 VYOHsiOCZ3lbdXJC3x-IYbSRirT9gsPyMC7T9gcBiL1LOm_HoPBk14WiBYh3uEioDQ9zI
534-5.7.14 PONsU-hvsTPui5RIjYcA5hbdGrtpMxnHbZ63pMfNHMKrZCV4MWOYhvlJdbShJg71>
534-5.7.14 Please log in via your web browser and then try again.
534-5.7.14  Learn more at
534 5.7.14  https://support.google.com/mail/answer/78754 a15sm5631279qkl.20 - gsmtp

  at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:965)
  at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:876)
  at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:780)
  at javax.mail.Service.connect(Service.java:388)
  at javax.mail.Service.connect(Service.java:246)
  at javax.mail.Service.connect(Service.java:195)
  at javax.mail.Transport.send0(Transport.java:254)
  at javax.mail.Transport.send(Transport.java:124)
  at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459)
  ... 2 more 

Here is my code: (I hid the password and the e-mail for security)

package bibliotecaemail;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

public class UsandoBibliotecaDeEmail {

    public static void main(String[] args) throws EmailException {

        Email email = new SimpleEmail();
        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator("[email protected]", "********"));
        email.setSSLOnConnect(true);
        email.setFrom("[email protected]");
        email.setSubject("Aula sobre uso de bibliotecas de terceiros");
        email.setMsg("Se etiver vendo este e-mail é porque o envio funcionou!");
        email.addTo("[email protected]");
        email.send();
        System.out.println("E-mail enviado!");

    }
}

OBS: I’ve already enabled access to mobile apps and still didn’t work.

Does anyone know what it can be?

  • 1

    Here I set a "mail.smtp.auth" property to "true", but it is using javamail

1 answer

0

  • 1

    Strange... It wouldn’t be necessary if you had activated the option of less secure apps. But I’m glad it worked!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.