I turned on IMAP in gmail settings. I dont have two-factor auth, only with single password.
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=${mymail}
spring.mail.password=${emailPassword}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=5000
spring.mail.properties.mail.smtp.writetimout=5000
public void sendMessage(){
SimpleMailMessage message = new SimpleMailMessage();
message.setTo("mymail@gmail.com");
message.setSubject("hello world");
message.setText("Hello world \n Spring boot");
emailSender.send(message);
}
@Override
public void run(String... args) throws Exception {
emailService.sendMessage();
}
What I am doing wrong?
exception:
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted.