首页 > 解决方案 > 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?

标签: keycloakgreenmail

解决方案


问题不是 greenmail 或 keycloak,而是在 keycloak 配置中使用的 docker => localhost 是 keycloak docker 容器的 localhost 映射,而不是 docker 主机(即运行它的系统)的映射。将 keycloak 的 smtp 主机更改为 'host.docker.internal' 解决了问题 => 这是在 docker 容器中获取主机 IP 地址的方法


推荐阅读