I want to send emails using gmail smtp server and spring mail sender, it doesn' throw any exceptions but my mail isn't sent i don't receive it.
Here's how Service looks:
@Service
public class MailSenderService {
@Autowired
public MailSender mailSender;
public void prepareAndSend(String recipient, String message) {
try {
SimpleMailMessage mail = new SimpleMailMessage();
String from = "testSender1@gmail.com";
String to = "testRecipient1@gmail.com";
String subject = "Test subject";
mail.setFrom(from);
mail.setTo(recipient);
mail.setSubject(subject);
mail.setText(message);
mailSender.send(mail);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
AppProperties
spring.mail.host = smtp.gmail.com
spring.mail.username = ********@gmail.com
spring.mail.password = ********
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.socketFactory.port = 465
spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback = false
spring.mail.properties.mail.smtp.ssl.enable = true
And pom dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
I deploy my app on port 8080 and just call this service with these two parameters, no exception is caught but in my testRecipient1 inbox i don't find any new mail, what have i missed ?