I use spring boot 2. I try to send mail. Server is outlook In my build.gradle
compile('org.springframework.boot:spring-boot-starter-mail')
In my facade class
for (FactoryEmailNC factoryEmail : factoryEmails) {
String message = mailContentBuilder.build(factoryEmail);
if (factoryEmail.getEmails() != null && !factoryEmail.getEmails().isEmpty()) {
mailService.sendHtmlMail(factoryEmail.getEmails(), "Not compliant", message);
//query to specify email has been sent.
setSampleEmailSent(factoryEmail);
}
}
private void setSampleEmailSent(FactoryEmailNC factoryEmail) {
....
samplesServices.setEmailsSent(testSampleIdEmailSent);
}
In my SamplesServices class
@Transactional
public void setEmailsSent(Map<String, List<SampleId>> testSampleIdEmailSent){
//call to repository, set flag email sent to true
...
}
public class MailServiceImpl(){
@Autowired
private JavaMailSender javaMailSender;
@Async
public void sendHtmlMail(List<String> to, String subject, String body) throws MessagingException {
MimeMessage mail = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mail, true);
...
helper.setTo(to.stream().toArray(String[]::new)); //line 64
javaMailSender.send(mail);
}
}
Actually email is sent, but setSampleEmailSent don't seem to be called because email flag still to false
org.springframework.mail.MailSendException: Failed messages: javax.mail.MessagingException: Exception reading response; nested exception is: java.net.SocketTimeoutException: Read timed out at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:490) ~[spring-context-support-5.1.5.RELEASE.jar!/:5.1.5.RELEASE] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:360) ~[spring-context-support-5.1.5.RELEASE.jar!/:5.1.5.RELEASE] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:355) ~[spring-context-support-5.1.5.RELEASE.jar!/:5.1.5.RELEASE] at com.mermacon.service.MailServiceImpl.sendHtmlMail(MailServiceImpl.java:64) ~[classes!/:na]
In my application properties
spring.mail.properties.mail.smtp.connectiontimeout=5000
spring.mail.properties.mail.smtp.timeout=3000
spring.mail.properties.mail.smtp.writetimeout=5000
spring.mail.properties.from=info@meracon.com
spring.mail.host=mail.oldubi.com
spring.mail.port=25
Any idea why email is sent but still get timeout?
Edit 1
I get timeout only if i send more then one email Log file of sending 1 email https://pastebin.com/6y6n8MV5
Log file after sending 1 email https://pastebin.com/j2sT7qHu
Edit 2
I put a thread sleep between every email sent, timeout disapear