To investigate what causes password reset emails to land in spam folders, start with one application-owned template and a fixed recovery origin. For B2B SaaS, that is a small, reviewable starting point: the message must reach its user while the reset link still works.

TL;DR: Password reset emails can land in spam because sender authentication fails or does not align, sending reputation is poor, or the message resembles unwanted mail. A template check can catch misleading content and unexpected links; it cannot certify inbox placement. Keep template ownership explicit, then inspect recipient-side authentication results and delivery evidence separately.

For the walkthrough below, a 10-minute lifetime is an illustrative application policy, not a universal recommendation. The application issues the reset token and expiry, renders the approved template, and hands the message to its mail transport. A recipient system evaluates the sender and message before deciding how to handle it. The application still validates expiry and single use when someone follows the link. A sentence in an email cannot enforce either rule.

1. Make template ownership executable

Start in a notebook with a deterministic renderer. Use Python 3.11 or later for this walkthrough. This example uses reserved example domains and a dummy token; it creates a message locally and sends nothing. Its three template decisions are the visible sender, the recovery destination, and the wording around expiry. The application team owns those values together so a copy edit cannot quietly introduce a second recovery origin.

from datetime import datetime, timedelta, timezone from email.message import EmailMessage from urllib.parse import urlencode, urlsplit SENDER = "Account Security <security@accounts.example.com>" RESET_ORIGIN = "https://accounts.example.com" TTL = timedelta(minutes=10) def render_reset(recipient, token, issued_at): if issued_at.tzinfo is None or issued_at.utcoffset() is None: raise ValueError("Use a timezone-aware issue time") if not token: raise ValueError("A reset token is required") expires_at = issued_at + TTL reset_url = RESET_ORIGIN + "/reset?" + urlencode({"token": token}) destination = urlsplit(reset_url) if destination.scheme != "https" or destination.netloc != "accounts.example.com": raise ValueError("Unexpected recovery origin") message = EmailMessage() message["From"] = SENDER message["To"] = recipient message["Subject"] = "Reset your account password" message.set_content( "We received a request to reset your account password.\n\n" f"Use this link: {reset_url}\n\n" "This link expires 10 minutes after the request.\n" "If you did not request this, you can ignore this email.\n" ) return message, expires_at issued_at = datetime(2026, 12, 5, 12, 0, tzinfo=timezone.utc) message, expires_at = render_reset( "reader@example.net", "demo-token-not-a-real-credential", issued_at ) assert expires_at == issued_at + TTL assert message["Subject"] == "Reset your account password" print(message.as_string()) 

The decision criterion is narrow: does the serialized message contain the sender, destination, and expiry wording the team approved? Python's standard email library handles message construction. The dummy token is deliberately unsuitable for a real reset flow; production token generation and redemption belong to the authentication service, outside this renderer.

Keep tokens private.

Printing this fixture is useful during development. Printing real reset messages into notebook output or production logs would expose recovery credentials. Moving notebook-to-prod means replacing that diagnostic output with a template revision and an internal request identifier. Neither should contain the token.

2. What actually sends a reset email to spam?

The renderer controls only part of the evidence a recipient sees. SPF authorizes sending hosts for an envelope domain. DKIM adds a domain signature. DMARC connects the visible From domain to an aligned SPF or DKIM authentication result and publishes a domain policy. These mechanisms address sender authentication; passing them does not promise inbox placement. Their specifications belong in a delivery investigation because a perfectly worded template cannot repair an unauthorized sending host or a domain-alignment mistake.

Inspect the received message.

Authentication-Results headers, as defined in RFC 8601, can report the recipient system's checks. Use a copy received by a controlled test mailbox and identify the headers added by that mailbox's trusted receiving infrastructure. An arbitrary header supplied by a sender is not equivalent evidence. Record the visible From domain, the reported authentication outcomes, and the template revision together; otherwise, a later content change can get blamed for an unrelated sender configuration change.

Recipient filtering also considers factors beyond those authentication mechanisms. Google's sender guidelines describe authentication, spam complaints, and sending practices as delivery concerns. Treat that guidance as evidence that these factors matter, not as a portable scoring formula for every mailbox. A successful transport handoff is likewise different from a verified inbox result. SMTP acceptance alone does not tell the application which folder the recipient will see.

Template ownership becomes useful here because it separates two investigations. If the received message has the wrong recovery destination or misleading wording, the template owner can reproduce and fix it. If the message is correct but authentication fails, changing the subject line is an ungrounded experiment. Route the evidence to whoever owns the sending domain and transport.

There is no universal list of forbidden words that guarantees delivery. Keep the purpose recognizable, avoid disguising the destination, and investigate observed results instead of polishing copy indefinitely.

3. Turn the template into a small evaluation set

Now add checks to the same Python session or file. These checks make the three ownership decisions reviewable without a mail account. They verify the message contract, including a token containing reserved URL characters, then confirm that a changed recovery host fails the evaluation. They do not simulate a spam classifier.

from urllib.parse import parse_qs def evaluate_template(message, expires_at, issued_at, expected_token): assert str(message["From"]) == SENDER assert str(message["Subject"]) == "Reset your account password" assert expires_at - issued_at == TTL body = message.get_content() links = [ line.removeprefix("Use this link: ") for line in body.splitlines() if line.startswith("Use this link: ") ] assert len(links) == 1 destination = urlsplit(links[0]) assert destination.scheme == "https" assert destination.netloc == "accounts.example.com" assert destination.path == "/reset" assert parse_qs(destination.query) == { "token": [expected_token] } assert "expires 10 minutes after the request" in body assert "If you did not request this" in body for token in ("fixture-123", "fixture+with/reserved?characters"): candidate, deadline = render_reset( "reader@example.net", token, issued_at ) evaluate_template(candidate, deadline, issued_at, token) changed, deadline = render_reset( "reader@example.net", "fixture-123", issued_at ) changed.set_content( changed.get_content().replace( "https://accounts.example.com", "https://unexpected.example.org" ) ) try: evaluate_template(changed, deadline, issued_at, "fixture-123") except AssertionError: pass else: raise RuntimeError("Evaluation missed a changed recovery host") print("Template fixtures passed; changed recovery host was rejected.") 

A passing evaluation means the fixtures satisfy this contract. Nothing more. Keep these explicit checks in the development harness; production input validation should raise explicit exceptions rather than depend on assertions, which Python can disable.

For an AI application builder, this is a useful place to resist adding a model call. A fixed reset message doesn't need fresh generation for every request. Keeping inference out of this path avoids per-message prompt cost and makes wording reproducible. If a model helps draft a revision during development, review the result as a proposed template change and run the same fixtures. Do not include live recovery tokens in that prompt.

The trade-off is editorial flexibility. Application-owned templates make changes depend on a deployment or configuration release, while externally managed templates can give another team direct editing access. Choose according to who must approve recovery wording and who can roll back a bad revision. If editing happens outside the application repository, export or fetch the actual rendered revision into the evaluation workflow; testing an old local copy leaves the important boundary untested.

Evaluate the version that ships.

4. Release against the expiry window

A spam investigation becomes more useful when it follows the user's deadline. For this example, queue age consumes part of a 10-minute lifetime. The production sender should check the remaining validity before handing off a message and apply an explicit policy for stale work. The authentication service must still reject expired or already redeemed tokens. Those are separate checks with different owners.

Before release, assign an owner for template approval and another for domain authentication if the responsibilities differ. Save the approved rendered fixture, verify authentication at controlled recipient mailboxes, and check the real recovery flow through expiry and redemption. During rollout, correlate template revisions with transport failures, queue age, and controlled mailbox observations. Keep real recipient addresses and token-bearing URLs out of ordinary diagnostic output.

Make retries bounded and observable. A timeout may leave the application uncertain about transport acceptance, so retry behavior needs to account for duplicate messages and token validity rather than assuming every timeout means nothing was sent. Password-reset request throttling and consistent responses also belong to the surrounding authentication flow; they prevent a delivery feature from becoming an account-discovery or message-flooding mechanism. The password recovery guidance below describes these controls.

If the message reaches spam, collect the received message and authentication evidence before changing copy. If it arrives after expiry, inspect queue and delivery timing. If a template revision changes the destination, block that revision with the local evaluation. Each observation points to a different next action, and template ownership makes those actions assignable.

Start with a repeatable message. Earn inbox confidence through observed delivery, then keep the recovery contract small enough to evaluate on every revision.

References

The authentication specifications define what those mechanisms establish. The sender guidance describes one receiving ecosystem's practices; it does not establish a universal inbox guarantee. The recovery guidance supports the surrounding security controls.

Further reading