Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Email: Must issue a STARTTLS command first

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


1 Answers

Add this property in your application.properties

spring.mail.properties.mail.smtp.starttls.enable=true

This work fine

like image 69
santiago correa alvarez Avatar answered Sep 07 '25 18:09

santiago correa alvarez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!