Keycloak not sending emails: how to fix SMTP
Why Keycloak does not send verification or password reset emails: host, port, SSL or StartTLS, sign-in, sender address, firewalls, and where the error shows.
- Author
- The RealmDeploy team
- Published
Keycloak sends email for a handful of jobs: verifying an address, resetting a password, admin-triggered actions, and invitations. When it cannot reach or sign in to the SMTP server, those jobs quietly stop working. Users wait for a message that never comes.
The settings live per realm, under Realm settings, on the Email tab. A realm with no Host set sends nothing at all. A realm with the wrong port, TLS mode or credentials fails on every message.
The tricky part is that the user often sees nothing useful. This post shows where the error really appears, how to find the cause, and how to fix it on Keycloak 26.x.
What you see
It depends on the flow. These are the messages in Keycloak 26.8.2:
-
Verify email shows an error page with this message from the login theme:
Failed to send email, please try again later. -
Forgot password shows the normal success message even when sending fails, so that the page does not reveal which accounts exist:
You should receive an email shortly with further instructions. -
Test connection on the Email tab reports an error, and the admin API behind it answers 500 with
Failed to send email.
In the server log, every failed send writes this line, followed by the underlying mail exception:
KC-SERVICES0029: Failed to send email
A failed password reset adds KC-SERVICES0026: Failed to send password reset email. A failed verification adds Failed to send verification email.
With saved events turned on, the failures appear as SEND_VERIFY_EMAIL_ERROR or SEND_RESET_PASSWORD_ERROR with the error email_send_failed. The event's reason holds Keycloak's own message, such as No email address configured for the user.
Causes, most common first
- The SSL and StartTLS switches do not match the port. The log shows a timeout, a handshake error or a TLS error right after connecting.
- Outbound SMTP is blocked. Connections time out. The default connection, read and write timeouts are 10,000 milliseconds each, so failures take about ten seconds.
- The SMTP server rejects the sign-in. The log shows an
AuthenticationFailedException. The provider may need an app password or a different sign-in method. - The From address is not allowed. The server accepts the sign-in but refuses the sender, or the message is accepted and later dropped as spam because SPF or DKIM fails.
- StartTLS is enabled but the server does not offer it. Since 26.8.1, Keycloak refuses to fall back to plain text. Sending started failing right after an upgrade.
- The user has no email address. Only that user is affected, and the event reason says so.
- The SMTP server's certificate is not trusted. A private CA or self-signed certificate on an internal relay fails the TLS check.
Ports, SSL and StartTLS
Most problems come down to this table. Pick one row.
| Port | What the server expects | Enable SSL | Enable StartTLS |
|---|---|---|---|
| 587 | Plain connection, then a STARTTLS upgrade | Off | On |
| 465 | TLS from the first byte | On | Off |
| 25 | Server-to-server relay, often blocked for clients | Usually off | On if the relay supports it |
Keycloak's Port field defaults to 25 when left empty. Do not turn on both switches. With Enable SSL on port 587, Keycloak tries a TLS handshake that the server does not expect, and the connection hangs or fails.
The 26.8.1 change matters here. Keycloak's upgrading guide says that when StartTLS is enabled, Keycloak now requires a successful STARTTLS upgrade before authentication or message data is sent, and that sending fails instead of falling back to plain text if the server does not support it. This fixes CVE-2026-107121. See SMTP StartTLS is required when enabled.
Diagnose it step by step
-
Turn on saved events in the admin console (Realm settings, Events, User events settings), then repeat the action. Read the event's error and reason.
-
Run Test connection on the Email tab. Your admin user needs an email address first; the console says so and offers a link to set one. The test sends a real message to that address.
-
Read the server log at the time of the test. Look for
KC-SERVICES0029and the exception below it. -
Turn on Enable Debug SMTP on the Email tab for one test. Keycloak then turns on the mail library's debug output, which prints the SMTP conversation to the server's console output and shows the exact step that fails. Turn it off afterwards, because the output gets very verbose.
-
Test the network path from the Keycloak host or container, not from your laptop:
# Port 587 with STARTTLS openssl s_client -connect smtp.example.com:587 -starttls smtp -crlf # Port 465 with TLS from the start openssl s_client -connect smtp.example.com:465 -crlfA timeout here means a firewall or network rule. A certificate error means a trust problem.
-
Check the user record. Open the user in the admin console and confirm the Email field is filled in.
-
Check the provider's side. Most SMTP services keep a log of rejected messages and the reason, such as an unverified sender.
Fixes
Match the switches to the port
For most hosted services, use port 587 with Enable StartTLS on and Enable SSL off. If the provider documents port 465, use it with Enable SSL on and Enable StartTLS off. Then run Test connection again.
You can set the same values with kcadm.sh. The keys are the realm's smtpServer attributes:
kcadm.sh update realms/acme \
-s 'smtpServer.host=smtp.example.com' \
-s 'smtpServer.port=587' \
-s 'smtpServer.starttls=true' \
-s 'smtpServer.ssl=false' \
-s 'smtpServer.auth=true' \
-s 'smtpServer.user=<smtp-user>' \
-s 'smtpServer.password=<smtp-password>' \
-s 'smtpServer.from=<from-address>'
The Email tab's password field also accepts a vault reference in the ${vault.ID} form, which keeps the secret out of the realm export.
Open the network path
Outbound SMTP is often blocked by default. Many cloud providers restrict outbound port 25, and Kubernetes network policies or corporate firewalls may block every SMTP port. Allow the Keycloak hosts to reach the provider's host on the port you chose. If port 25 is blocked, use 587 or 465 instead.
Fix the sign-in
- Use the SMTP user name the provider gives you. With some services it is not your email address but a fixed name or an API key id.
- Use an app password or SMTP key where the provider asks for one. Account passwords protected by two-step sign-in are usually refused for SMTP.
- Keycloak 26.8 also offers token sign-in for SMTP: set Authentication Type to Token on the Email tab. Use it if your provider requires OAuth for SMTP.
Use an allowed From address
Set From to an address on a domain you control and have verified with the provider. Then publish the SPF and DKIM records the provider gives you, so receiving servers accept the mail. Envelope from, if set, is the address used for bounces. Reply to is optional.
A From address on a domain you do not control will be rejected by the provider, or marked as spam by the receiver.
Turn StartTLS off only for a server that has no TLS
If an internal relay really does not support TLS, the upgrading guide's advice is to disable Enable StartTLS if you intentionally use plain SMTP without TLS. Only do that on a network you trust. A better fix is to enable STARTTLS on the relay.
Trust a private certificate
If the relay uses a certificate from your own CA, add that CA to Keycloak's truststore. In Keycloak 26:
bin/kc.sh start --truststore-paths=/opt/keycloak/conf/internal-ca.pem
Fill in the user's email
A user without an email address cannot receive anything. Add it in the admin console, or let the user add it through the account console.
Check organizations after 26.8.2
Keycloak 26.8.2 requires a verified email before automatic, domain-based organization membership through a linked identity provider. The upgrading guide asks you to configure and test the realm's SMTP settings before upgrading, because users whose addresses need local verification cannot finish onboarding without email. See Email verification before domain-based organization membership.
On RealmDeploy
The Email tab is yours: you set host, port, TLS switches, credentials and sender in your realm. Outgoing connections from your Keycloak are closed by default. Tell us your SMTP server's host and port, and we open that one destination for your tenant. Until then, Test connection times out. If the server uses a certificate from a private CA, tell us that too, because Keycloak's truststore is set on our side. See Isolation and Before you go live.
If Test connection still fails after we have opened the path, write to us from the dashboard or with the contact form with the time of the test, and we check the server log for that moment.
Tools that help
- Event types reference: look up
SEND_VERIFY_EMAIL,SEND_RESET_PASSWORDand the other email-related events. - kcadm command builder: build the
kcadm.sh update realms/...command for the SMTP settings. - Admin API curl builder: read or set the realm's
smtpServersettings through the Admin REST API. - X.509 decoder: read the SMTP server's certificate from the
openssl s_clientoutput and check its issuer and dates.
Keep reading
Keycloak CORS errors: causes and fixes
Why the browser blocks calls to Keycloak with a CORS error, how Web origins work, how to find the real status code behind it, and how to fix each cause.
Keycloak "HTTPS required": causes and safe fixes
What the Keycloak "HTTPS required" page means, how Require SSL decides, how to get back into a locked master realm, and why turning SSL off is the wrong fix.
Keycloak invalid_grant: causes and fixes
Why the Keycloak token endpoint answers invalid_grant: reused or expired codes, redirect_uri mismatches, ended sessions, stale refresh tokens and PKCE.