Build server with new Email Provider

Hi, all!

It has been awhile since I last did anything meaningful in Java, so I’m a little lost with the deployment process.

According to docs, I have to do:

1. Copy JAR file to /providers/ directory.
2. Run  kc.sh build --spi-email-sender-provider=myprovider

However, I’m getting this error bellow:

ERROR: org.keycloak.email.EmailSenderProviderFactory: jar:file:///opt/keycloak/lib/../providers/notifier-1.0-SNAPSHOT.jar!/META-INF/services/org.keycloak.email.EmailSenderProviderFactory:1: Illegal configuration-file syntax
For more details run the same command passing the '--verbose' option. Also you can use '--help' to see the details about the usage of the particular command.

Passing the --verbose parameter do not work, so I’m not sure if there are anything else to add here.

What other information should I provide would help solving this?

Thank you in advance!

What’s the content of that file? It should be a single line with the fully-qualified class name of your implementation.

Hi! Thank you for the quick reply.

I was using the fully qualified, but realized I named my classes wrongly:

my.fully.qualified.name.email.Email**Send**ProviderFactory
instead of
my.fully.qualified.name.email.EmailSend**ER**ProviderFactory (capitalized to illustrate)

After that and a few teaks in the re-implementations, it built successfully. I still have to verify the deployment and will update it here as soon as possible.

Cheers!

1 Like

Okay! Tests done!

It builds, but it seems like it is not being used. I get the following at the top of my logs:

keycloak_dev_composed | 2023-02-16 21:47:06,562 WARN  [org.keycloak.services] (build-103) KC-SERVICES0047: mysender (mysender.keycloak.provider.email.mysender.MySenderEmailSenderProviderFactory) is implementing the internal SPI emailSender. This SPI is internal and may change without notice

This is the send method with the UserModel signature.

    @Override
    public void send(Map<String, String> config, UserModel user, String subject, String textBody, String htmlBody) throws EmailException {

        String from = config.get("from");
        String fromDisplayName = config.get("fromDisplayName");
        String replyTo = config.get("replyTo");
        String replyToDisplayName = config.get("replyToDisplayName");
        
        System.out.println(from);
        System.out.println(fromDisplayName);
        System.out.println(textBody);
        
        LOGGER.info(replyTo);
        LOGGER.info(from);
        
        LOGGER.debug(replyTo);
        LOGGER.debug(from);
    }

The other send method is not implemented: just the signature and a empty body.

Nothing shows up in the logs besides the startup message and I do get the e-mail on my box, so the flow still works using the original classes. My SMTP configuration is still there on my Realm, I’m not sure if that affects anything.

This is the command line I’m using to build KC it:

/opt/keycloak/bin/kc.sh build --spi-email-sender-provider=mysender --spi-email-sender-provider-mysender-enabled=true

PS: I’m running it in a container, though I don’t believe this affects anything.

UPDATE:

My sender shows up in the Provider list of Master’s realm. But I don’t know how to see which one is in use (except with the test I did in last post)

Cheers!

Do you provide the spi selection/enable flags to the startup command as well?

I’m not sure. I will say “no”. I followed this instructions (Configuring providers - Keycloak), but I may have skipped or not fully understand how to use it.

EDIT:

I’m providing this on my startup:

/opt/keycloak/bin/kc.sh start-dev --log=console,file --log-file=/opt/keycloak/logs --features=admin-
fine-grained-authz --db $DB_VENDOR --db-url jdbc:postgresql://172.20.0.5/keycloak_server --db-username $DB_USER --db-password $DB_PASSWORD

Perhaps, there are options missing.

Thanks!

If you use start-dev the previous build will have no effect as it will perform it again on startup.

What happens if you provide the spi flags to the start-dev?

1 Like

Hey! Thanks for the reply!

I managed to get it working. I added --spi-email-sender-provider=mysender --spi-email-sender-provider-mysender-enabled=true to the start-dev and it did the trick.

Cheers!

1 Like