Spring boot deployed to war doesnt send google emails


I have a spring boot app which when I run I can succesfully send email messages, however when I deploy it to war on my AWS server it suddenly cant send emails and throws me error:

org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbsv
534-5.7.14 GyjozMVw6yK71QY1-533Cq9j3pFvZ4Qk6tvNi8jraY2Qr1olGNIenIvjiHO8PYS2clGWG_
534-5.7.14 AKcP6Ny-ZwLVxAyKeqgAnOqFPC-fC2Ha4fZuHlbiWsi8wYfeQzgoSjzBowz9R4uYWPocKY
534-5.7.14 yY7pG1k4O7ukaHccwVpLm8ypHX_MuWoiYbKFE6bSG5ht7Jps1MoPoWpE21oDtiu0udijNz
534-5.7.14 zwKkTw01RQUyNDlkJkjHWqkGQW1GM> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14  Learn more at
534 5.7.14  https://support.google.com/mail/answer/78754 s20sm9437528wmb.9 - gsmtp


private String recipient;

private JavaMailSender javaMailSender;

public SimpleStatusObject sendEmail(SimpleEmail simpleEmail) throws MessagingException, UnsupportedEncodingException {
    MimeMessage message = javaMailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message);

    helper.setReplyTo(simpleEmail.getSenderEmail(), simpleEmail.getSenderName());

    return new SimpleStatusObject(Status.SUCCESS, "message sent");


spring.mail.host = smtp.gmail.com
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.socketFactory.port = 465
spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback = false

Credential are okay and I have enabled less secured apps in my account settings. I don't know whats the problem.

Show source
| java   | email   | spring   | spring-boot   | gmail   2017-01-07 19:01 1 Answers

Answers to Spring boot deployed to war doesnt send google emails ( 1 )

  1. 2017-01-07 19:01

    I found the solution. Problem was not with spring. It's just sometimes "allowing access for less secured apps" isn't enough.

    Here are some more informations why google may won't allow access. https://support.google.com/accounts/answer/6009563

    First tip is to:

    1. go to: https://g.co/allowaccess
    2. allow login from different device.
    3. use different device to login.

    And this is what helped in my case.

    All credits to: http://serverfault.com/questions/635139/how-to-fix-send-mail-authorization-failed-534-5-7-14

Leave a reply to - Spring boot deployed to war doesnt send google emails

◀ Go back