Open lucasbasquerotto opened 6 months ago
Can you try to initialize the connection factory without the builder:
SmtpConnectionFactory cf = new SmtpConnectionFactory(Session.getDefaultInstance(props), newSessiontStrategy(),
newConnectionStrategy(smtphost, smtpUser, smtpPassword), true );
The true at the end is to invalidate the connection in case of any exception.
Connection factory should then be closer to your example by using without the pool.
@nithril Thanks for the response. I don't know the how to call newSessionStrategy()
and newConnectionStrategy(smtphost, smtpUser, smtpPassword)
, in regards with which imports are needed (in the README this method is just exposed briefly with outdated links).
I saw that the true
argument is a boolean parameter invalidateConnectionOnException
, so I think it's equivalent to define that in the builder. I created the connection factory as follows:
SmtpConnectionFactory factory = SmtpConnectionFactoryBuilder
.newSmtpBuilder()
.session(props)
.protocol(SMTP_PROTOCOL)
.host(SMTP_HOST)
.port(SMTP_PORT)
.username(SMTP_USER)
.password(SMTP_PASSWORD)
.invalidateConnectionOnException(true)
.build();
In my tests, the error 451 4.4.2 Timeout waiting for data from client.
still happens, but when I try to send after that it works for some time (I think about 1min), then the error happens again, then it works for some time, then the error happens again, and so on...
This already helps in the sense that the errors won't just happen indefinitely (after the error it starts working again), but it's still far from the ideal. Previously, this error never happened. I don't know what it did under the hood before, if it verified if the connection was active before sending, or retrying when the error happens, but having this error happen about every minute is still very bad, but at least that already helps to mitigate the problem, and I think it's one step closer to a real solution.
We updated Wildfly that is used as our java server, and with this change, we updated Java 11 to Java 20 and occurrences of
javax
tojakarta
, but we received errors in some libraries, this being one of them.The version we used of this lib was
1.2.2
, and thejavax
tojakarta
was adressed in the most recent version.After the version of this lib was updated, we received no compile errors, and we were able to send emails. But soon after, we receive errors in the following order:
The first error when trying to send emails is:
The next error (when we try to send again):
If we try to send again, we receive the following error:
From then on, we receive the above error for every call.
If we restart Wildfly, the emails are sent again for a short time, then the errors above start happening and never ends (before restarting again).
The code we use is the same as the one we used with version
1.2.2
of this lib, except for the change in the imports ofjavax.mail
tojakarta.mail
.If I change the code to not use this library and use the raw java mail (without pooling), it works even after the Wildfly/Java upgrade.
The code below (without pooling) works:
The code below works only for a short time, but then starts giving the errors above (but worked previously):
The connection pool is created as follows:
When I tested without pooling (which works), we use the same props and get a session using it:
The
MimeMessage
was also created the same way in both cases. My guess is that for some reason the connection expires but is not discarded when we use the connection pool (but this error didn't happen previously).We use SES for sending emails, if that is relevant.
I saw a similar case from 2019 at https://github.com/nithril/smtp-connection-pool/issues/20, but no solution so far.
Is there a way to solve this issue?