我有一个应用程序,用户请求报告并将其作为压缩的csv文件附件在她的收件箱中获取。 它适用于发送带有最大44kb的zip文件的电子邮件。但程序永远陷入困境 Transport.send(消息);行,同时发送更大尺寸的报告。
我搜索类似问题并应用了超时解决方案,但它对我没有帮助。
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);
}