I have an application, user requests report and gets it in her inbox as zipped csv file attachment. It works fine for sending emails with zip file with max ~ 44kb. But program get stuck forever on Transport.send(message); line, while sending reports with bigger size.
I search similar issues and applied the timeout solution, but it does not help me.
try {
Properties props = mailProperties.asProperties();
props.put("mail.smtp.connectiontimeout", TIMEOUT);
props.put("mail.smtp.timeout", TIMEOUT);
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mailProperties.getUsername(), mailProperties.getPassword());
}
});
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(mail.getFrom()));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(mail.getTo()));
message.setSubject(mail.getSubject());
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(mail.getText());
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.attachFile(filePath);
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
message.setContent(mp);
Transport.send(message); // get stuck here
} catch (Exception e) {
LOGGER.error("Error : ", e);
throw new RuntimeException("Sending email failed.", e);
}