Keycloak email delivery with SMTP and Microsoft 365 OAuth

Keycloak sends verification, password reset and other account emails through a realm-level SMTP configuration. This page explains the settings, the Microsoft 365 OAuth path, the 26.8 StartTLS change and how to test each realm.

On this page

Why Keycloak emails fail to arrive and what keycloak email delivery requires

This page explains how to make Keycloak's account emails, such as verification and password reset messages, arrive reliably, covering SMTP settings, enforced StartTLS since Keycloak 26.8, XOAUTH2 authentication for Microsoft 365, sender domain records and per-realm delivery testing. When users cannot verify accounts or reset passwords, or administrators see mail stuck in a queue, the cause is usually not in Keycloak's login logic. Keycloak sends account mail from the email settings of each realm, so every realm can point at a different server, account and sender address.

Delivery depends on four layers that are often owned by different teams: the SMTP server or Microsoft 365 tenant, the authentication method Keycloak uses to log in, the TLS negotiation between Keycloak and that server, and the DNS records that prove the sender domain is allowed to send. The mail team may own the mail relay, the identity team the realm settings, and the DNS team the SPF, DKIM and DMARC records. A failure in any one layer looks the same to the user, which is why the work needs one owner who can test each layer in turn.

Plan this work when a new realm goes live and its email settings have never been tested, when the organization moves Keycloak mail from basic SMTP to Microsoft 365, when a Keycloak 26.8 upgrade starts rejecting mail that used to pass because StartTLS is now enforced, or when recurring messages land in spam. Before starting, confirm with your mail administrator which sending method your tenant still allows, which sender address each realm will use and who can change the DNS records. Those answers decide the scope of the work more than the Keycloak settings do.

How a Keycloak account email travels from realm to inbox

The flow starts when a user action in a realm, such as registration verification, a password reset or a required action, asks Keycloak to send a message. Keycloak then uses the realm's SMTP settings to open a connection to the mail provider, with the connection expected to use TLS. The trust boundary sits at that hop: inside it, Keycloak holds the credentials, either basic or an OAuth token for Microsoft 365, and outside it, the provider hands the message to the recipient's mail system, which checks sender authentication records before delivery. Administrators most often see failures at the connection and authentication step, and at the sender records check, where the message is rejected or lands in spam.

Path of one account email from the realm's SMTP settings to the recipient's inbox, with the trust boundary marked.

Which SMTP and authentication options fit which mail setup

This table compares the realm email settings a team must decide before verification and password reset mail can leave Keycloak. Read each row against your mail provider and your ownership model, then confirm the encryption mode before any move to Keycloak 26.8, because StartTLS is enforced without plaintext fallback in that release.

SettingWhen it fitsOwnership and rotation
SMTP host and portRelay or submission service your mail team already runs for transactional mailOwned by the mail team; confirm the port with your provider and the server administration guide, not from memory
Encryption: StartTLSRequired on Keycloak 26.8 and later, where plaintext fallback is not allowed; confirm the server accepts the upgrade before cutoverCertificate changes on the mail server can break sign-in mail, so monitor certificate expiry on the relay
Encryption: SSL/TLS (implicit)Provider mandates a TLS-wrapped connection on its submission portConfirm the port and mode in writing with the provider; port choice is provider-specific
Authentication: noneInternal relay that accepts mail only from trusted network addresses, in a restricted networkAccess depends on network controls, so review who can reach the relay whenever routing changes
Authentication: basic username and passwordSMTP relay or hosted mail service that still issues a static login for applicationsSecret lives in the realm settings; rotate on a schedule and whenever an admin leaves
Authentication: XOAUTH2Microsoft 365 tenants where basic SMTP authentication is not an option and an app registration is approvedClient secret or certificate in the app registration needs an expiry owner; token flow is set by the tenant admin
Sender address and display nameDedicated no-reply address on a domain your team controls and has authenticatedSender domain records (SPF, DKIM, DMARC) belong to the DNS owner, so changes need that owner's sign-off
Shared credentials across realmsOne mailbox or relay serves several realms with one policySingle rotation event affects every realm; one compromised secret exposes all of them
Per-realm credentialsRealms with separate owners, brands or regulatory boundaries that need separate sender identitiesMore secrets to rotate and more realm-level settings to test, but each owner controls their own mail path

Basic SMTP or XOAUTH2 for Microsoft 365: choosing the authentication path

Use this path when Keycloak sends mail through an SMTP server or relay that accepts a username and password, such as an internal mail gateway or a transactional email provider's SMTP endpoint. Keycloak stores the SMTP settings for each realm and authenticates with the basic credentials you provide, so the security of the path depends on the relay's configuration and on how the secret is handled.

  • Relay ownership: Confirm who operates the relay, which sending domains it accepts, and whether it is allowed to send to external recipients for verification and password reset messages.
  • Transport security: Since Keycloak 26.8, SMTP StartTLS is enforced without plaintext fallback, so confirm the relay offers StartTLS on the port you configure before cutover.
  • Credential storage: Keep the SMTP password out of realm exports and version control, and confirm who can read it in the admin console and in your secrets manager.
  • Credential rotation: Record who owns the mail account, how the password is rotated and which realms or environments share it.
  • Relay limits: Ask the relay operator about sending quotas and rate limits that could delay bulk or repeated reset messages.

Before committing, confirm the relay's current authentication and TLS requirements with its operator and check the SMTP settings in the Keycloak server administration guide.

How to configure and test email delivery for each realm

This sequence takes an SMTP or Microsoft 365 mail setup from provider choice to verified delivery, with a documented result for every realm. Each realm keeps its own email settings, so each one needs its own test pass.

  1. Confirm the mail provider and authentication method

    The platform owner and the messaging or identity administrator agree on which mail service relays Keycloak messages, which SMTP host and port it uses, and whether it accepts basic credentials or requires OAuth 2.0 with XOAUTH2 for Microsoft 365. Record the decision, the service account, and who holds its secret. The step is done when the team can name the host, port, and authentication method in writing and the mail provider has confirmed that the account may send from the chosen address.

  2. Set the sender address and domain

    The DNS owner confirms that the sender domain publishes the sender authentication records your mail provider requires, and the realm sender address is chosen to match that domain. Check with your provider which records apply to your setup, since the exact records depend on the service. The step is done when a test message from the sender address passes the provider's domain checks and the address is one users will recognize as legitimate.

  3. Configure SMTP settings in the realm email tab

    An administrator opens the realm's Email tab in the admin console and enters the sender address, host, port, and authentication settings confirmed in the first step. Keep the TLS setting on, since Keycloak 26.8 enforces StartTLS without plaintext fallback for SMTP. Save the change and confirm that the values reflect what the provider expects. The step is done when the settings are saved in this realm and no secret appears in exported configuration or logs.

  4. Confirm TLS negotiation in a production-like environment

    The platform team tests the same host, port, and network path in a non-production environment that matches production, including any proxy or egress firewall. Watch the Keycloak server log while sending, and confirm that the connection upgrades to TLS and that no message is sent in plaintext. If the upgrade fails, the send should fail rather than fall back. The step is done when the log shows a negotiated TLS session and the team has noted any firewall rule that blocked the mail port.

  5. Send a test message from the admin console

    From the realm's Email tab, an administrator uses the test connection action and sends a test message to a mailbox the team controls. Check that the message arrives in the inbox rather than the spam folder and that the displayed sender matches the configured address. If the test fails, the error in the server log identifies whether the problem is authentication, TLS, or network reachability. The step is done when the test message arrives with the expected sender name and address.

  6. Trigger verification and password reset emails per realm

    For each realm, a tester creates a test user with a mailbox the team controls, then triggers the verification email and the password reset email from the login flow or the user's account page. Each realm must be tested on its own because email settings are stored per realm, and a working realm does not prove that another one is configured. The step is done when both messages arrive for every realm, and the link in each message points to the expected public frontend hostname rather than an internal address.

  7. Check message headers and sender authentication results

    The tester opens the raw headers of each received message and reviews the authentication results the receiving mailbox records for SPF, DKIM, and DMARC. Confirm that the From domain aligns with the sender domain configured in step two and that the link host matches the realm's frontend URL. The step is done when the results show the expected pass values, and any failure is traced to a DNS record or provider setting and fixed before sign-off.

  8. Record the results for each realm

    The team writes a short test record per realm listing the SMTP host, port, authentication method, TLS result from the server log, the test send outcome, the verification and reset message results, the header check, and the tester and date. Keep the record with the realm's change history so that the next upgrade or provider change can repeat the same checks. The step is done when every realm has a signed-off record and any open item has a named owner.

Why sender domain authentication decides whether reset emails reach the inbox

Receiving mail systems decide whether to trust a message partly by checking whether the sending domain has authorized the server that sent it and whether the message carries a valid signature from that domain. Those checks depend on DNS records that the domain owner publishes, not on anything Keycloak does. A realm can be configured with a sender address such as a no-reply mailbox on your domain, and Keycloak will send from it without complaint, yet the receiving server can still reject the message or file it in spam because your DNS does not authorize the sending server or sign its messages. Verification and password reset emails are often the first mail a user ever receives from a new realm, so this gap shows up as failed sign-ups and locked-out users rather than as an error in Keycloak.

Ownership of this work is split, and the split is where projects stall. The identity team controls the SMTP or Microsoft 365 connection settings in each realm. The DNS owner publishes the records. The email security team decides which authentication methods the domain must pass and how strict the published policy should be. Before go-live, ask the mail provider in writing which sender records it requires for your domain, which signing keys it uses, and whether it supports a dedicated sending subdomain so that other mail from the same domain is not affected. Ask for the exact record values and the date each one was last verified, not a general description of the setup.

Treat the records as a launch dependency with its own check. Confirm the required records with your mail provider and your email security team, publish them, then send test messages from each realm's configured sender address to mailboxes at several large providers and read the authentication results in the message headers. Repeat this after any change to the sender address, the provider, or the DNS zone, because a record change made for another system can break Keycloak mail without any change in Keycloak itself.

Securing SMTP credentials, email content and the mail path

Email delivery touches credentials, user-facing links and a network path that many teams never review. The controls below cover how the SMTP password or OAuth client secret is stored, who may change mail settings, how the transport is encrypted, which host builds reset links, which networks reach the relay and how changes are recorded.

Protect the mail credential at rest

The SMTP password or the Microsoft 365 OAuth client secret is stored in realm email settings, so an admin who can open the realm may be able to read it in an export or a log. Confirm how the credential is supplied in your deployment, whether through a secret store or an environment variable, and confirm that realm exports and admin REST responses mask it. Rotate the credential on a schedule your team can follow and record who holds it.

Keycloak docs

Limit who edits realm email

Changing the SMTP host or sender address lets someone redirect password reset and verification mail to a server they control. Restrict the manage-realm permission to a named group of administrators, and keep realm administration separate from application owners. Review that group whenever someone changes role, because a single broad admin account can alter mail routing for every user in the realm.

Enforce encrypted transport

Keycloak 26.8 enforces StartTLS for SMTP with no plaintext fallback, so a relay that cannot negotiate TLS will fail rather than send in the clear. Confirm that the relay presents a certificate Keycloak trusts, that the hostname matches, and that the relay you point to is the one your mail team operates. Test the connection after any certificate renewal, since a failed handshake will stop reset mail without an obvious error to users.

Upgrade notes

Build reset links from the public host

Password reset and verification links are built from the frontend URL. If a reverse proxy forwards requests with a different or internal host name, links can point to an address users cannot reach or to a host an attacker controls. Follow the production guide by serving public frontend URLs on one hostname and the admin console on another, then confirm the configured hostname is the one that appears in a test email.

Production guide

Restrict which networks reach the relay

Keycloak should reach the mail relay on a defined path, and nothing else should be able to use that relay as an open sender. Confirm with your network team which source addresses and ports may connect to the relay, whether the relay requires authentication from Keycloak's address, and whether outbound rules block direct delivery from other hosts. Document this path so a security review can verify it.

Audit changes to mail settings

Changes to realm email configuration should leave a record of who changed what and when. Enable admin event logging for realm updates and forward those events to your log platform, so a change to the SMTP host or sender is visible to the security team. Ask your team to confirm that the audit trail includes the realm and the acting administrator, and test that a deliberate change produces an entry.

How to keep email working after go-live

Email delivery needs an owner after go-live, because the settings that made it work will drift. Mail credentials and OAuth client secrets expire or get rotated, sender DNS records change when the mail provider or domain changes, and each Keycloak upgrade can alter how mail is sent. Agree on a rotation schedule with the customer's security team, record who owns each mail credential, and tie every rotation to a test send so a broken secret is found during a planned change rather than when a user cannot reset a password.

Decide what counts as a mail failure before you configure alerting. Keycloak writes send errors to its server log, so the operations team should know which log category and message patterns indicate a failed verification or password reset email, and should route those events to the people who can act on them. If you already run Prometheus or ship logs to Loki, OpenSearch or a SIEM, add a rule for repeated send failures and a rule for authentication errors against the mail server. Dedicated mail metrics were not covered in the research behind this page, so confirm with your Keycloak version's observability documentation which mail-related metrics it exposes before building dashboards around them.

Recheck delivery whenever something outside Keycloak changes. A new mail provider, a changed SPF or DKIM record, a new sending domain or a tightened policy at the provider can break messages that worked the week before. Run the same test sends you used at go-live, from every realm that sends mail, and confirm the messages land in the inbox rather than the spam folder. Keep a short runbook entry that lists each realm, its sender address and the test recipient.

Retest every realm after each Keycloak upgrade, not only the realm you changed most recently. The upgrade notes for each release should be read for mail-related changes, such as the enforced StartTLS behavior introduced in 26.8, before the upgrade is scheduled. Ask your implementation partner, or confirm internally, who performs this retest, what evidence is kept, and how a failed test blocks the upgrade from reaching production.

Limits to confirm for your Keycloak and mail environment

Email delivery depends on settings in three places: the Keycloak release you run, the mail provider or Microsoft 365 tenant that relays messages, and the network path between them. Confirm each limit with the person who owns it before you design the configuration, because a setting that works in a test realm can still fail under your tenant rules or your sending quota.

Exact SMTP settings and XOAUTH2 support

Confirm which email settings your Keycloak release accepts and whether it supports XOAUTH2 for your mail flow. Keycloak 26.8 enforces StartTLS without plaintext fallback, so a relay that only offers plaintext or a port that does not negotiate StartTLS will fail after an upgrade. Check the upgrade notes for your exact version and test with the relay your mail team operates. Ask the platform owner who holds the release and upgrade plan.

Upgrade guide

Microsoft 365 tenant and modern authentication

Confirm with the Microsoft 365 administrator whether modern authentication is available for the mailbox or service account that sends mail, and whether the tenant allows the OAuth app registration that XOAUTH2 requires. Tenant policies, conditional access rules and disabled legacy protocols can block a sender even when the Keycloak settings are correct. Ask for the policy names that apply to the sending identity so you can test against them.

Relay limits and sending quotas

Ask the mail provider for the per-minute, per-day and per-recipient limits on the relay or mailbox Keycloak will use. Verification and password reset traffic can spike during a login campaign or an incident, and a throttled relay delays or drops codes that users need to sign in. Confirm whether the provider applies different limits to authenticated and anonymous senders, and who pays for higher volume.

Realm email templates and theme scope

Confirm whether your realms need custom email templates, languages or branding. Default templates work for basic verification and reset flows, but changed wording, logos or localized text belong to the theme work described in the themes and extensions group, and that work carries its own upgrade cost. Ask the product owner which realms need branded mail and whether any template must include legal text that compliance has approved.

Links behind a load balancer or proxy

Verify the frontend hostname that Keycloak uses to build links in verification and reset emails. If the reverse proxy forwards requests with an internal hostname or without the expected forwarded headers, users receive links that point to a private address or fail. Test a reset from outside the network, check the link host in the message, and confirm the setting with the team that owns the load balancer and the public DNS record.

Mail event logging for compliance

Confirm with your compliance lead whether the framework you follow requires records of sent messages, delivery failures or access to mail credentials. Keycloak and the mail provider log different events, and neither may retain them for as long as your control set expects. Ask which log fields, retention period and review owner the auditors will test, then decide where mail events are shipped and who can read them.

Questions teams ask before they hire help with Keycloak email

What drives the cost and effort of a Keycloak email project?

The main drivers are the number of realms that send mail, the mail provider you use, how much access the project has to your Microsoft 365 tenant, how many DNS records must change, and how much testing you require. A single realm sending through an SMTP relay you already run is a small job. Several realms with different sender addresses, a Microsoft 365 tenant that needs an app registration and admin consent for XOAUTH2, and DNS changes that go through a separate team take longer and involve more people. Each of these is a cost component you can ask a partner to price separately. Ask for the scope list in writing before work starts.

Can our team set up Keycloak email delivery alone?

Often yes, if the people involved already know the relevant systems. The work needs a Keycloak administrator who can edit realm SMTP settings and test them, a mail administrator who understands your relay or Microsoft 365 mail flow, and someone who can create and verify DNS records for SPF, DKIM and DMARC on the sender domain. If you use Microsoft 365 with OAuth, a tenant administrator must register the application and grant consent. Teams that lack one of these skills usually lose time waiting on others rather than on technical work, so confirm who holds each role before you decide.

How long does it take to get verification and reset emails working?

The duration depends on the drivers rather than on a fixed number. Timing is shaped by how quickly your tenant administrator can approve an application registration, how long DNS changes take to propagate in your environment, how many realms need separate sender settings, and how many test cycles the security or compliance team requires before sign-off. Teams with a staging realm and test mailboxes ready tend to move faster. Ask any provider to show the sequence of steps and the approvals each step depends on, and ask which steps you control.

What does the project need from our side?

Plan for five kinds of input before work starts. You need tenant administrator access, or a named administrator who will perform the app registration and consent steps. You need the owner of the sender domain's DNS zone to add or approve SPF, DKIM and DMARC records. You need test mailboxes that receive mail from each realm, and a staging Keycloak where configuration changes can be tried first. You also need a Keycloak administrator who can review the realm settings, and a named approver for production changes. Confirm each owner and their availability in the written scope.

Does the upgrade to Keycloak 26.8 change the email work?

Yes, it changes one important setting. Keycloak 26.8 enforces SMTP StartTLS without plaintext fallback, so an SMTP connection that previously downgraded to plaintext will now fail if the server does not support StartTLS. Before you upgrade, check each realm's SMTP configuration, confirm that your relay offers StartTLS on the port you use, and test a verification email in staging. The upgrade notes for the release describe this change, and the Keycloak upgrading guide is the place to confirm the exact behavior for your version.

What should a fixed-scope quote for this work list?

A written quote should list the realms in scope, the mail path for each (relay SMTP or Microsoft 365 with XOAUTH2), and whether Microsoft 365 app registration is included or handed to your administrator. It should name the DNS records covered for each sender domain, the test cases run per realm (verification, password reset, and any admin notifications), and the staging and production steps. It should state the deliverables, such as configuration documentation and a test record, the customer inputs and their owners, and what happens if a dependency is late. Ask which items are one-time work and which recur, such as credential rotation or support.

Which Keycloak skills does the work need, and who provides them?

The work draws on three skill sets: Keycloak realm and SMTP administration, mail administration for the relay or Microsoft 365 mail flow, and DNS and tenant administration. Your team may already have the first two, but the third often sits with a separate group. When you ask a partner for help, ask which of these skills the partner will supply and which must come from your staff. DeployOpen implements and documents self-hosted open-source platforms in your own infrastructure, so the configuration and evidence stay in your environment.

How DeployOpen scopes and delivers Keycloak email work

DeployOpen treats Keycloak email as a delivery path to verify, not a single settings page. We scope the SMTP and Microsoft 365 OAuth work in writing, build it inside your infrastructure, test each realm and hand over the configuration and runbook your team operates.

How we scope

  • We agree in writing which realms, email flows and sender domains the engagement covers before work starts.
  • We record your Keycloak version, mail relay or Microsoft 365 tenant details and current email failures as scope inputs.
  • We confirm with your mail and identity owners who approves the sending mailbox, app registration and DNS changes.

How we build

  • We configure SMTP settings with enforced StartTLS, so the connection never falls back to plaintext.
  • We set up XOAUTH2 authentication for Microsoft 365 where your tenant policy requires it, using the mailbox and app permissions you approve.
  • We document sender domain authentication records and test verification and password reset emails in each realm.

How we hand over

  • You receive the realm-by-realm email configuration, test results and DNS and tenant settings used in the build.
  • We deliver a runbook covering credential rotation, failed-delivery checks and what to change when a mail provider alters its policy.
  • Handover sessions walk your administrators through the test procedure so they can repeat it after changes.

How we support

  • Most engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer, including re-testing after Keycloak upgrades.
  • Ask for a written quote that follows from the agreed scope, since DeployOpen does not publish a price list.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.