title: Unable to send email via smtp.gmail.com without enabling 'Access for less secure apps' flag
body: <p>Gmail prevents sending email if '<em><a href="https://www.google.com/settings/security/lesssecureapps" rel="nofollow noreferrer">Access for less secure apps</a></em>' is not Turned On, </p>
  
  <p>I am using spring-boot and sending email using class:</p>
  
  <pre><code>org.springframework.mail.javamail.JavaMailSenderImpl
  </code></pre>
  
  <p>It fails with message:</p>
  
  <pre><code>org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 534-5.7.14
  </code></pre>
  
  <p>It works only if I enable the flag '<em>Access for less secure apps</em>', I want to send an email without enabling that flag, any suggestions?</p>
  
  <p>here is my configuration:</p>
  
  <pre><code>@Bean
  public JavaMailSender emailSender() {
      JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
      javaMailSender.setHost("smtp.gmail.com");
      javaMailSender.setPort(465);
      javaMailSender.setJavaMailProperties(getMailProperties());
      javaMailSender.setUsername(from);
      javaMailSender.setPassword(password);
      return javaMailSender;
  }
  
  
      private Properties getMailProperties() {
      Properties properties = new Properties();
      properties.setProperty("mail.transport.protocol", "smtp");
      properties.setProperty("mail.smtp.auth", "true");
      properties.setProperty("mail.smtp.starttls.enable", "true");
      properties.setProperty("mail.debug", "false");
      properties.setProperty("mail.smtp.starttls.required", "true");
      properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
      return properties;
  }
  </code></pre>