Reputation:
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
[email protected]
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("[email protected]");
messaggio.setFrom("[email protected]");
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
Upvotes: 4
Views: 8050
Reputation: 389
You might need to add this property to your application.properties
:
spring.mail.properties.mail.smtp.starttls.required=true
If you still need more diagnostic information in your log files regarding sending e-mail, you can also add this to the application properties:
spring.mail.properties.mail.debug=true
Upvotes: 0
Reputation: 81
Add this property in your application.properties
spring.mail.properties.mail.smtp.starttls.enable=true
This work fine
Upvotes: 8