|
10 | 10 | import org.simplejavamail.mailer.config.TransportStrategy;
|
11 | 11 | import org.simplejavamail.mailer.internal.mailsender.MailSender;
|
12 | 12 | import org.simplejavamail.converter.internal.mimemessage.MimeMessageHelper;
|
| 13 | +import org.simplejavamail.util.ConfigLoader; |
| 14 | +import org.simplejavamail.util.ConfigLoader.Property; |
13 | 15 | import org.slf4j.Logger;
|
14 | 16 | import org.slf4j.LoggerFactory;
|
15 | 17 |
|
@@ -83,6 +85,12 @@ public class Mailer {
|
83 | 85 |
|
84 | 86 | private static final Logger LOGGER = LoggerFactory.getLogger(Mailer.class);
|
85 | 87 |
|
| 88 | + /** |
| 89 | + * the default maximum timeout value for the transport socket is {@value #DEFAULT_SEND_MAIL_SOCKET_TIMEOUT} |
| 90 | + * milliseconds. Can be overridden from a config file or through System variable. |
| 91 | + */ |
| 92 | + private static final String DEFAULT_SEND_MAIL_SOCKET_TIMEOUT = "60000"; |
| 93 | + |
86 | 94 | private final MailSender mailSender;
|
87 | 95 |
|
88 | 96 | /**
|
@@ -229,6 +237,14 @@ public static Session createMailSession(final ServerConfig serverConfig, final T
|
229 | 237 | props.put(transportStrategy.propertyNameHost(), serverConfig.getHost());
|
230 | 238 | props.put(transportStrategy.propertyNamePort(), String.valueOf(serverConfig.getPort()));
|
231 | 239 |
|
| 240 | + // socket timeouts handling |
| 241 | + String sendMailTimeoutInMillis = ConfigLoader.valueOrProperty( |
| 242 | + null, Property.DEFAULT_SEND_MAIL_TIMEOUT_IN_MILLIS, DEFAULT_SEND_MAIL_SOCKET_TIMEOUT |
| 243 | + ); |
| 244 | + props.put("mail.smtp.connectiontimeout", sendMailTimeoutInMillis); |
| 245 | + props.put("mail.smtp.timeout", sendMailTimeoutInMillis); |
| 246 | + props.put("mail.smtp.writetimeout", sendMailTimeoutInMillis); |
| 247 | + |
232 | 248 | if (serverConfig.getUsername() != null) {
|
233 | 249 | props.put(transportStrategy.propertyNameUsername(), serverConfig.getUsername());
|
234 | 250 | }
|
|
0 commit comments