title: Spring Mail Sender using Gmail SMTP error . How can I fixed?
body: <p>I've never used it before. I can't run. I have getting error list </p>
  
  <p>Here is my application properties.spring.mail.username What can I use ? my gmail account and password right ?</p>
  
  <pre><code>spring.mail.host=smtp.gmail.com
  spring.mail.port=587
  spring.mail.username=xxxx@gmail.com
  spring.mail.password=xxxxx
  
  #mail properties
  spring.mail.properties.mail.smtp.auth=true
  spring.mail.properties.mail.smtp.starttls.enable=true
  </code></pre>
  
  <p>And this is my main class </p>
  
  <pre><code>@SpringBootApplication
  public class MarterTravelApplication extends SpringBootServletInitializer implements CommandLineRunner {
  
      @Autowired
      @Qualifier("javasampleapproachMailSender")
      public MailSender mailSender;
      public static void main(String[] args) {
          SpringApplication.run(MarterTravelApplication.class, args);
  
      }
  
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
          return application.sources(MarterTravelApplication.class);
      }
  
      public void run(String... arg0) throws Exception {
  
          String from = "xxxxxx@gmail.com";
          String to = "xxxxx@gmail.com";
          String subject = "JavaMailSender";
          String body = "Just-Testing!";
  
          mailSender.sendMail(from, to, subject, body);
      }
  </code></pre>
  
  <p>And then my mail sender class is </p>
  
  <pre><code>package com.marter.travel;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.mail.SimpleMailMessage;
  import org.springframework.mail.javamail.JavaMailSender;
  import org.springframework.stereotype.Component;
  
  @Component("javasampleapproachMailSender")
  public class MailSender {
  
      @Autowired
      JavaMailSender javaMailSender;
  
      Logger logger = LoggerFactory.getLogger(this.getClass());
  
      public void sendMail(String from, String to, String subject, String body) {
  
          SimpleMailMessage mail = new SimpleMailMessage();
  
          mail.setFrom(from);
          mail.setTo(to);
          mail.setSubject(subject);
          mail.setText(body);
  
          logger.info("Sending...");
  
          javaMailSender.send(mail);
  
          logger.info("Done!");
      }
  }
  </code></pre>
  
  <p>my error code is-like that javax.mail.AuthenticationFailedException How can I fixed that error</p>
  
  <pre><code>org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.5.8.RELEASE.jar:1.5.8.RELEASE]
  Caused by: org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 534-5.7.14 &lt;https://accounts.google.com/signin/continue?sarp=1&amp;scc=1&amp;plt=AKgnsbtJ
  534-5.7.14 jo4gUzPM-ZGj5a92U0ymdgCJ6Zu00ISucB5c1CQLTB1zwZM3QY6KKIIXcxDHVOW4cwQXXc
  534-5.7.14 tTNoxOzv8WMBebiW06gwl_J9nhMY1krJtWud9R-3ZrZvym73YvCXLRy5yjhcFg3jP25rme
  534-5.7.14 Lq02oyvHyD79OexP-qqsH3eudTCcIeKr8siLZA8a4aH-fekwGDyJXpeCihR8Rq2OsDiyXO
  534-5.7.14 -1GfeQloALfGx7kWKoF6LLl-o3p7s&gt; 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 z129-v6sm61960461pfb.108 - gsmtp
  
      at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:424) ~[spring-context-support-4.3.12.RELEASE.jar:4.3.12.RELEASE]
      at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:307) ~[spring-context-support-4.3.12.RELEASE.jar:4.3.12.RELEASE]
      at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) ~[spring-context-support-4.3.12.RELEASE.jar:4.3.12.RELEASE]
      at com.marter.travel.MailSender.sendMail(MailSender.java:29) ~[classes/:na]
      at com.marter.travel.MarterTravelApplication.run(MarterTravelApplication.java:34) [classes/:na]
      at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:732) [spring-boot-1.5.8.RELEASE.jar:1.5.8.RELEASE]
      ... 11 common frames omitted
  Caused by: javax.mail.AuthenticationFailedException: 534-5.7.14 &lt;https://accounts.google.com/signin/continue?sarp=1&amp;scc=1&amp;plt=AKgnsbtJ
  534-5.7.14 jo4gUzPM-ZGj5a92U0ymdgCJ6Zu00ISucB5c1CQLTB1zwZM3QY6KKIIXcxDHVOW4cwQXXc
  534-5.7.14 tTNoxOzv8WMBebiW06gwl_J9nhMY1krJtWud9R-3ZrZvym73YvCXLRy5yjhcFg3jP25rme
  534-5.7.14 Lq02oyvHyD79OexP-qqsH3eudTCcIeKr8siLZA8a4aH-fekwGDyJXpeCihR8Rq2OsDiyXO
  534-5.7.14 -1GfeQloALfGx7kWKoF6LLl-o3p7s&gt; 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 z129-v6sm61960461pfb.108 - gsmtp
  
      at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:932) ~[javax.mail-1.5.6.jar:1.5.6]
      at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:843) ~[javax.mail-1.5.6.jar:1.5.6]
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:748) ~[javax.mail-1.5.6.jar:1.5.6]
      at javax.mail.Service.connect(Service.java:366) ~[javax.mail-1.5.6.jar:1.5.6]
      at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:501) ~[spring-context-support-4.3.12.RELEASE.jar:4.3.12.RELEASE]
      at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:421) ~[spring-context-support-4.3.12.RELEASE.jar:4.3.12.RELEASE]
      ... 16 common frames omitted
  </code></pre>