简体   繁体   English

JavaMail 连接超时不按属性工作

[英]JavaMail connection timeout is not working as per properties

Javax mail version used 1.6.2使用的 Javax 邮件版本 1.6.2

manually setting JavaMailSender手动设置 JavaMailSender

Timeout thing I tried with mail.smtp.timeout & mail.smtps.timeout.我用 mail.smtp.timeout 和 mail.smtps.timeout 尝试过的超时。
And, I tried with both String & Integer value 3000.而且,我尝试使用 String 和 Integer 值 3000。

    String timeOut = "3000";
    Properties pros = new Properties();
    pros.put("mail.smtp.timeout", timeOut);
    pros.put("mail.smtp.connectiontimeout", timeOut);
    pros.put("mail.smtp.writetimeout", timeOut);

    pros.put("mail.smtp.auth", "true");
    pros.put("mail.smtp.starttls.enable", "true");


    jmailSender.setJavaMailProperties(pros);

    return jmailSender;

It's taking around 7 seconds without any fail.大约需要 7 秒,没有任何失败。 Since by default is infinite, so most probably it is not setting somehow由于默认情况下是无限的,所以很可能它没有以某种方式设置

Are any properties missing or something else?是否缺少任何属性或其他内容?

The properties mail.smtp.connectiontimeout and `mail.smtps.connectiontimeout only apply while establishing the connection.属性mail.smtp.connectiontimeout和 `mail.smtps.connectiontimeout仅在建立连接时适用。 It is not related to any timeouts during transport.它与传输期间的任何超时无关。

The properties mail.smtp.timeout and mail.smtps.timeout are related to the time blocked waiting for a read.属性mail.smtp.timeoutmail.smtps.timeout与阻塞等待读取的时间有关。 This is related to reading SMTP response codes.这与读取 SMTP 响应码有关。

The properties mail.smtp.writetimeout and mail.smtps.writetimeout are related to writing chunks of data which can vary in size.属性mail.smtp.writetimeoutmail.smtps.writetimeout与写入大小不同的数据块有关。

None of these timeouts represent a deadline for a single transaction of sending a mime message.这些超时都不代表发送 mime 消息的单个事务的最后期限。 What is happening is that there is no single action (connect, read, write) that is exceeding the 3000ms.正在发生的事情是没有超过 3000 毫秒的单个操作(连接、读取、写入)。

For example, connect could take 1000ms, follow by say 30 requests (write) and response parsing (reads) that take 100ms, and set of say 3 writes to send the message that take 1000ms each due to the speed of the network and size of the message.例如,连接可能需要 1000 毫秒,然后是 30 个请求(写入)和响应解析(读取),需要 100 毫秒,并且一组说 3 次写入发送消息,每个需要 1000 毫秒,因为网络速度和大小消息。 That is 1000 + (30 * 100) + (3 * 1000) = 7000ms total time but no single action exceeded the timeouts.即 1000 + (30 * 100) + (3 * 1000) = 7000 毫秒总时间,但没有单个操作超过超时。

In a test environment在测试环境中

  1. Set all timeouts to 3000.将所有超时设置为 3000。
  2. Set connectimeout to 1 and test.connectimeout设置为 1 并进行测试。 You should see the connection fail.您应该看到连接失败。
  3. Restart the test by setting it back to 3000 and set timeout to 1. You should see the reads fail.通过将其设置回 3000 并将timeout设置为 1 来重新启动测试。您应该会看到读取失败。
  4. Restart the test by setting it back to 3000 and set writetimeout to 1. You should see the transport fail.通过将其设置回 3000 并将writetimeout设置为 1 重新启动测试。您应该会看到传输失败。

If the test doesn't act this way you either haven't set the properties correctly (typo or smtp vs. smtps).如果测试没有以这种方式运行,您要么没有正确设置属性(错字或 smtp 与 smtps)。 Or you are really lucky to have such low latency.或者你真的很幸运有这么低的延迟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM