keycloakgreenmail

greenmail - keycloak connection doesn't work


I'm trying to write some integration tests on my keycload flows. To validate the registration and password forgotten mails, I would like to use greenmail.

my docker configuration of greenmail (within docker compose):

greenmail:
      image: greenmail/standalone:1.5.7
      environment:
      - GREENMAIL_OPTS=-Dgreenmail.setup.test.all -Dgreenmail.hostname=0.0.0.0 -Dgreenmail.auth.disabled -Dgreenmail.verbose
      ports:
      - "3025:3025"
      - "3143:3143"

And my keycloak email config: enter image description here

when I click on "test connection", it doesn't work and I get in my logs: enter image description here error message (for those who can't open/display the image):

Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 3025; timeout 1000;
    nester exception is: Connection refused

someone knows what I'm missing?


Solution

  • the issue wasn't greenmail or keycloak, but docker => localhost, which was used in the keycloak config, is the localhost mapping of the keycloak docker container, not of the docker host (i.e. the system running it). changing the smtp host of keycloak to 'host.docker.internal' solved the issue => this is the way to get the host ip address within a docker container