simple-java-mail
simple-java-mail copied to clipboard
reusing jakarta.mail.Transport for multiple without using batch-module
I'd like to reuse a SMTP connection (and therefore jakarta.mail.Transport) for sending more that one email. I'd like to have some API that can be used like this:
try(MailerTransport transport = mailer.openTransport())
{
for(int i = 0; i<5; i++)
{
transport.sendMail(EmailBuilder.startingBlank().
...
withSubject("mail " + i + "/5"));
}
}
I can't use batch-module, as it wants to maintain threads and the message queue for me. I have just one thread fetching emails from the database and sending it to smtp blockingly. No need for parallel threads or connections pools. Just one thread reusing the transport for more than one email.
I made this possible with hacking simple-java-mail, but it says: "Providing access to Session instance for emergency fall-back scenario. Please let us know why you need it." So here I am.
Best regards, Ralf.