KeyCloak fails to send email using SMTP with status 500

Viewed 2501

I have Keycloak running in a Kubernetes cluster. Authentication works but I need to set up e-mail to be able to send e-mails for verification and password reset.

I have SendGrid set up as an SMTP Relay. These settings (host, port and api key) work when I send mail using the SendGrid java client. However, when pressing Test connection in KeyCloak I get:

[Error] Failed to load resource: the server responded with a status of 500 () 
[Debug] Remove message (services.js, line 14)
[Debug] Added message (services.js, line 15)
[Error] Can't find variable: error
https://<domain>/auth/resources/ong8v/admin/keycloak/js/controllers/realm.js:76 – "Possibly unhandled rejection: {}"
[Debug] Remove message (services.js, line 14)

There isn't much to go on here. I have an e-mail address set up for the currently logged in user. I've also tried resetting the password in case the Test connection functionality was broken but that didn't work either.

The Realm Settings settings user for email are as such:

host: smtp.sendgrid.net
port: 587
from: test@<domain>
Enable StartTLS: true
Username: "apikey"
Password: <api key>

Any idea what can be wrong? Or how to find out? For instance, maybe I can get a more meaningful error message somehow.


Edit:

I got the server logs.

Failed to send email: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.sendgrid.net, 587; timeout 10000;
nested exception is: java.net.SocketTimeoutException: connect timed out

Edit 2:

I've tried sending mail using Telnet using the exact same settings and that works. So apparently it's something with Keycloak or its underlying Java libraries that's causing issues sending e-mail.

1 Answers

Turns out that Keycloak works and that emails were blocked by the hosting provider.

Related