Skip to content

Bug: batch-module gives error when there is a custom mailer #375

@andrus

Description

@andrus

I am using SJM 6.x via Bootique integration. One feature that I need myself and is being requested by other Bootique users is the ability to override recipients of a message for testing purposes. Something like this:

transport.sendMessage(message, testRecipients);

This is ideal for QA, as it preserves the real To, Cc, Bcc, but delivers to a designated test mailbox. I tried implementing it as a CustomMailer in Bootique. Unfortunately it is not easy to do it, as the presence of CustomMailer prevents SJM stack from configuring itself properly. So a call like this results in an NPE:

@Override
public void sendMessage(
    OperationalConfig operationalConfig, 
    Session session, 
    Email email, 
    MimeMessage message) {
    try {
        TransportRunner.sendMessage(operationalConfig.getClusterKey(), session, message, overriddenRecipients);
    } catch (MessagingException e) {
        ...
    }
}
java.lang.NullPointerException: Connection pool used before it was initialized. This shouldn't be possible.
at java.base/java.util.Objects.requireNonNull(Objects.java:246)
at org.simplejavamail.internal.batchsupport.BatchSupport.acquireTransport(BatchSupport.java:110)
at org.simplejavamail.mailer.internal.util.TransportRunner.sendUsingConnectionPool(TransportRunner.java:84)
at org.simplejavamail.mailer.internal.util.TransportRunner.runOnSessionTransport(TransportRunner.java:72)
at org.simplejavamail.mailer.internal.util.TransportRunner.sendMessage(TransportRunner.java:48)

Wanted to ask for an expert opinion on a better way to do a custom dispatch via TransportRunner. Or maybe there's interest to make recipient override feature (which has been quite handy with a different mail stack) a part of SJM?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions