Search code examples
javaspringmacosgmail

Getting AuthenticationFailedException in the Spring Framework JavaMailSenderImpl class


I have the Spring Framework Application located on my OS X (Maverick) computer. I use gmail.

Our Spring Framework application uses the org.springframework.mail.javamail. JavaMailSenderImpl class to send email. This part of the code throws AuthenticationFailedException

protected void doSend(MimeMessage[] mimeMessages, Object[] originalMessages) throws MailException {
    Map<Object, Exception> failedMessages = new LinkedHashMap<Object, Exception>();

    Transport transport;
    try {
        transport = getTransport(getSession());
        transport.connect(getHost(), getPort(), getUsername(), getPassword());
    }
    catch (AuthenticationFailedException ex) {
        throw new MailAuthenticationException(ex);
    }

For host I use smtp.gmail.com, for port: 587. I also use username and password from my regular gmail login.

I have a peer with the same setup, for him sending email works.


Solution

  • Go to the Google account, in Sign-in & security one needs to allow less secure apps for using gmail. That's it