I am trying to send a simple email to myself using Spring Email, but I'm encountering the following exception:
org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. p4sm7233776wrx.63 - gsmtp
; message exceptions (1) are:
Failed message 1: com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. p4sm7233776wrx.63 - gsmtp
By googling it I saw that most people fixed this by adding the property spring.mail.properties.mail.smtp.starttls.enable=true, but I have already done it and isn't working in my case.
My application.properties:
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=myEmail@gmail.com
spring.mail.password=********
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true
My code:
@Service
@Slf4j
public class NotificationService {
@Autowired
private JavaMailSender javaMailSender;
public void sendNotification() {
SimpleMailMessage messaggio = new SimpleMailMessage();
messaggio.setTo("myEmail@gmail.com");
messaggio.setFrom("YourSpringFriend@gmail.com");
messaggio.setSubject("Test Spring Email");
messaggio.setText("Tadaaaa! Email da Spring!");
javaMailSender.send(messaggio);
}
}
What am I doing wrong?
Thanks in advance for your time and experience