javaguicejava-17jamesapache-james

Java: Apache James In-Memory Mail Server Fails to Start?


I am attempting to embed a memory only instance of Apache James in a Java application but running into an error.

I'm following the example here:

GitHub Sample Project

Apache James Website

The error I receive is:

Failed to start application (with profile [dev]): org.apache.commons.configuration2.ex.ConfigurationException: You need to configure a Processor with name error

Here's my code:

private static final Module PROTOCOLS = Modules.combine(
        new IMAPServerModule(),
        new ProtocolHandlerModule(),
        new MailRepositoryTaskSerializationModule(),
        new SMTPServerModule());

private static final Module CUSTOM_SERVER_MODULE = Modules.combine(
        new MailetProcessingModule(),
        new MailboxModule(),
        new MemoryDataModule(),
        new MemoryEventStoreModule(),
        new MemoryUsersRepositoryModule(),
        new MemoryMailboxModule(),
        new MemoryQuotaModule(),
        new MemoryMailQueueModule(),
        new TaskManagerModule(),
        new RawPostDequeueDecoratorModule(),
        binder -> binder.bind(MailetContainerModule.DefaultProcessorsConfigurationSupplier.class)
                .toInstance(BaseHierarchicalConfiguration::new));

private static final Module CUSTOM_SERVER_AGGREGATE_MODULE = Modules.combine(
        CUSTOM_SERVER_MODULE,
        PROTOCOLS);

private final GuiceJamesServer inMemMailServer;

public MailServerImpl() {
    Configuration config = Configuration.builder()
            .workingDirectory(myConfigDir)
            .configurationPath(new Configuration.ConfigurationPath(myConfigDir))
            .build();

    this.inMemMailServer = GuiceJamesServer
            .forConfiguration(config)
            .combineWith(CUSTOM_SERVER_AGGREGATE_MODULE);
}

Solution

  • I resolved this by adding the missing configuration files for the embedded Apache James server. The server requires the configs found in this example from their GitHub repo

    You must include the smtpserver.xml file, the mailrepositorystore.xml file and the mailetcontainer.xml file from the example in order for the server to start. You should also include the imapserver.xml file if you wish to use the IMAP functionalities.

    One more thing to note is that the page above on the James website is not up to date (at time of writing) with the example project. If you look at the example in the GitHub there are a handful of differences between that example code and the website sample code.

    If embedding in another web application like I am you'll want to store your XML configurations at the root of your resources folder for the least configuration to start.