Updated 2026-11-20
How to Configure SMTP Email in Keycloak
In the Keycloak admin console pick the realm, open Realm settings -> Email, set From to an address on your domain, Host to smtp.bulko.io, Port to 587, tick Enable StartTLS, switch Authentication on and enter your Bulko SMTP username and password. Click Test connection (your admin user needs an email address) and then Save; repeat for every realm that sends mail.
Keycloak has no mail server of its own and no global SMTP setting: every realm carries its own smtpServer configuration, entered in the admin console under Realm settings -> Email. Until a realm has one, everything in it that depends on email is broken or hidden: Forgot password links, Verify email on registration, the Credential Reset emails admins send from a user's Credentials tab (Update Password, Configure OTP, Verify Email), the Verify Existing Account By Email step of identity provider linking, and notifications from the email event listener (login errors, password and OTP changes).
When the mail does fail, users mostly see Failed to send email, please try again later. on the login page, while the server log gets KC-SERVICES0029: Failed to send email with the real cause underneath. Everything below is for the current Keycloak 26.x admin console (checked against 26.8.2).
Keycloak SMTP settings
| Field | Value |
|---|---|
| From | [email protected] (a domain you control) |
| From display name | Your app or company name (optional) |
| Reply to | [email protected] (optional) |
| Envelope from | Leave empty |
| Host | smtp.bulko.io |
| Port | 587 (or 2525; 465 with Enable SSL). Empty means 25, which is not offered |
| Encryption | Enable StartTLS on for 587/2525; Enable SSL only for 465, never both |
| Authentication | On; Authentication Type: Password |
| Username | Your Bulko SMTP username (smtp_xxxxxxxxxxxxxxxx) |
| Password | Your Bulko SMTP password, or ${vault.smtp-password} |
One SMTP config per realm: master vs. your app realms
SMTP settings are stored inside each realm and are not inherited. Configuring master only covers mail for master realm users, which in most setups are just the Keycloak administrators (their own password resets and event notifications). Your applications' users live in other realms, and each of those needs its own Email tab filled in. The same goes for a realm created by import: if the JSON had no smtpServer object, the realm has no mail.
- You can use the same Bulko credentials in several realms; the 2,000 emails per day cap applies per SMTP access, so all realms sharing one login share that cap.
- If tenants should send from different domains, give each realm its own From address and verify each domain in Bulko (up to 10 domains per account).
Step-by-step setup
- Buy an SMTP package on the Bulko SMTP Relay page and copy the username and password from Dashboard -> SMTP Access. Verify your domain under Sending domains so mail from your realm is DKIM-signed.
- Make sure the admin account you are logged in with has an email address (user menu top right -> Manage account, or Users in the master realm). Without one, Test connection stays greyed out with the hint To test the connection you must first configure an e-mail address for the current user.
- In the admin console, choose the realm your applications use from the realm selector (not
master, unless you mean it), then open Realm settings and the Email tab. - Under Template, fill in From (required) with an address on your verified domain and, optionally, From display name and Reply to. Leave Envelope from empty.
- Under Connection & Authentication, set Host to
smtp.bulko.ioand Port to587, and tick Enable StartTLS under Encryption. Leave Enable SSL off. - Switch Authentication to on, keep Authentication Type on Password, and enter your Bulko Username and Password (or a
${vault.…}reference, see below). - Click Test connection; once you get the success message, click Save.
- Turn on the features that need mail: Realm settings -> Login -> Forgot password and Verify email, and optionally the
emaillistener under Realm settings -> Events. Repeat steps 3-7 for every other realm.
smtp.json + kcadm.sh (set SMTP for a realm from the CLI)
# smtp.json - only the smtpServer object; other realm settings stay unchanged
{
"smtpServer": {
"from": "[email protected]",
"fromDisplayName": "My App Login",
"replyTo": "[email protected]",
"host": "smtp.bulko.io",
"port": "587",
"starttls": "true",
"ssl": "false",
"auth": "true",
"authType": "basic",
"user": "smtp_xxxxxxxxxxxxxxxx",
"password": "${vault.smtp-password}"
}
}
# apply to one realm (repeat per realm), from inside the container:
/opt/keycloak/bin/kcadm.sh config credentials --server http://localhost:8080 \
--realm master --user admin
/opt/keycloak/bin/kcadm.sh update realms/myrealm -f smtp.json
/opt/keycloak/bin/kcadm.sh get realms/myrealm --fields smtpServer
Automating it: kcadm.sh, realm JSON and the vault
In the realm representation the Email tab is the smtpServer object, and all values are strings: host, port, from, fromDisplayName, replyTo, replyToDisplayName, envelopeFrom, starttls, ssl, auth, authType (basic = Password, token = XOAUTH2), user, password, plus connectionTimeout, timeout and writeTimeout in milliseconds (default 10000) and debug. Ship it in a realm export for --import-realm or push it with kcadm.sh as shown above.
To keep the password out of the database and out of exported JSON, use a vault. Build Keycloak with --vault=file, start it with --vault-dir=/path/to/secrets and put the Bulko password into a file named <realm>_smtp-password there (with the default resolver the realm name is prefixed; underscores inside names must be doubled). In the Password field you then enter ${vault.smtp-password}. Keycloak resolves the reference when it sends; if the secret is not found, it falls back to the literal text and the login fails with 535.
Send a test email
Test connection sends a real message, not just a handshake: it uses the values currently in the form (even unsaved ones) and mails the email address of the admin who is logged in, as the hint above the button says (When testing the connection an e-mail will be sent to the current user). The button is disabled until From holds a valid address and Host is filled in. Success shows Success! SMTP connection successful. E-mail was sent!. A failure only shows Error! Failed to send email; the real reason (a 535 reply, a TLS error, a timeout) is in the Keycloak server log, e.g. docker logs keycloak or kubectl logs.
If you are logged in as the master realm admin and testing another realm, the test still goes to that master admin's address. For an end-to-end check, click Forgot Password? on the realm's login page for a test user, or use Credential Reset -> Send Email on the user's Credentials tab. To see the SMTP dialogue, switch on Enable Debug SMTP temporarily and watch the log, then switch it off again.
Enable SSL vs. Enable StartTLS in Keycloak
| Port | Enable SSL | Enable StartTLS |
|---|---|---|
| 587 (recommended) | off | on |
| 2525 (if 587 is blocked) | off | on |
| 465 | on | off |
Keycloak's docs suggest port 465 when you tick an encryption box; that is only right for Enable SSL. Enable SSL on 587 makes Keycloak talk TLS to a server expecting plain SMTP first, typically ending in Unrecognized SSL message, plaintext connection? or a read timeout. In recent 26.x releases Enable StartTLS also makes STARTTLS mandatory: if the server does not offer it, sending stops instead of falling back to plain text. Bulko's certificate is a public Let's Encrypt one, so Keycloak's default Java truststore accepts it and no truststore changes are needed.
Troubleshooting
| Problem | Fix |
|---|---|
| Test connection is greyed out | From is invalid, Host is empty, or your admin account has no email address. Add an email to your admin user (usually in master) and reload the tab. |
| Log shows jakarta.mail.AuthenticationFailedException: 535 ... | Wrong Bulko username or password, or Authentication is off. Re-copy both from Dashboard -> SMTP Access, keep Authentication Type on Password, and if you use ${vault.…} check that the vault file name includes the realm prefix. See the 535 error guide: /en/smtp-errors/535/. |
| Unrecognized SSL message, plaintext connection? or Could not convert socket to TLS | Encryption does not match the port. Use 587 or 2525 with only Enable StartTLS ticked, or 465 with only Enable SSL ticked. |
| Couldn't connect to host, port: smtp.bulko.io, 25; timeout 10000 | The Port field is empty, so Keycloak used 25. Enter 587. If 587 also times out, the host or Kubernetes network policy blocks outbound SMTP; try 2525 or open egress to smtp.bulko.io. |
| Users see Failed to send email, please try again later. but Test connection works | The user's realm is not the one you configured, or the user has no email address. Check the Email tab of that exact realm and look for KC-SERVICES0029 in the log for the underlying error. |
| Reset and verification emails land in spam | The From domain is not verified. Add the DKIM record bk1._domainkey.<domain> from Bulko's Sending domains page, the optional bnc.<domain> CNAME and a DMARC record; check SPF/DMARC with /en/validators/spf-checker/. |
FAQ
Why does Keycloak say I must configure an e-mail address for the current user?
Test connection always mails the admin who is logged in, so that admin needs an email in their own profile. Add it via Manage account in the user menu or under Users in the master realm; it does not affect where realm users' mail goes.
Do I have to configure SMTP in the master realm?
Only if master realm users (usually administrators) need password resets or event emails. Application realms do not inherit it; each realm that sends mail needs its own Email tab settings.
Can I keep the SMTP password out of the realm export?
Yes. Enable the file or keystore vault and enter ${vault.smtp-password} in the Password field; the real secret stays in the vault and the realm only stores the reference.
Does Keycloak need XOAUTH2 or the token settings for Bulko?
No. Token (XOAUTH2) is for providers such as Microsoft 365 that issue OAuth tokens (see /en/smtp-relay/microsoft-365-basic-auth/). Bulko uses username and password (LOGIN or PLAIN), so choose Password.
How much does it cost?
Bulko SMTP Relay is a one-time package: $5 for 5,000 emails, $15 for 20,000, $30 for 50,000 or $60 for 150,000, with no subscription and no expiry. Each SMTP access can send up to 2,000 emails per day.
Get SMTP credentials for Keycloak
One-time payment by card or crypto, no subscription. Unused emails never expire. 2,000 emails per day per SMTP account.
What you can send: Acceptable Use Policy.