New guide: how to warm up a dedicated IP without hurting your reputation. Read now →
Log in
MigoSMTP
Getting startedUpdated 26 Oct 2026

Passwordless Login by Email: Magic Links and Codes Without Breaking Deliverability or Security

How email magic links and one-time codes work for sign-in, security properties, link scanners that consume tokens, expiry and single-use rules, deliverability requirements, UX details, abuse controls and a build checklist.

IR
Written by Ishita Rao
Email Authentication Engineer
Reviewed by Omar Haddad
  • Published23 Dec 2024
  • Read time6 min
  • Length1,235 words
Share this guide

Passwordless login by email replaces a memorised password with proof that you control a mailbox. The user enters an address, receives a message containing either a link that signs them in (a magic link) or a short code to type, and gets in. Done well, it removes password reuse, resets and a large class of phishing. Done carelessly, it moves the whole security of the account into one fragile place: the delivery of an email, which can be slow, filtered, delayed, forwarded or pre-fetched by security software. A sign-in email that arrives late or never is a locked-out customer, and a link that works for anyone who holds it is an open door. This guide covers how the flows work, what makes them secure, how scanners and clients interfere, what deliverability they need and a checklist for building them. It builds on password reset emails, OTP emails and rate limits and backoff.

Magic linkA single-use, short-lived URL with an unguessable token; one tap signs in
CodeA short numeric or alphanumeric one-time code typed back into the original page
RisksDelays, scanners that consume tokens, phishing look-alikes, token leakage in logs and referrers
BasicsHigh entropy, single use, short expiry, same-browser binding where possible, strict rate limits

The two flows compared

PropertyMagic linkOne-time code
User actionOpen the email and tap the linkRead the code and type it into the page that requested it
DeviceMay open on a different device or browser than the one that askedEntered in the original session, so the request and completion are bound together
Security strengthsLong random token, hard to guess; no typingShort-lived; attacker needs both the session and the code
WeaknessesLink scanners may open and consume it; forwarding or sharing gives access; opens in the wrong browser (in-app browser)Easy to phish by asking the user to read the code aloud; guessing risk if the code is short and attempts are not limited
Mobile experienceExcellent when the mail app opens the right browserCopy and paste or autofill from a notification or the one-time-code hint
AccessibilityLink must be keyboard reachable and clearScreen readers can read short codes, but long ones are tiring
Deliverability sensitivityBoth rely entirely on prompt deliverySame

Security rules

  1. Use high-entropy tokens. A link token should have at least 128 bits of randomness from a cryptographic generator, stored hashed on the server like a password.
  2. Make them single use. Invalidate the token the moment it is used, and when a new request replaces the old one.
  3. Keep expiry short. Ten to fifteen minutes is common for sign-in links and codes. Longer lifetimes increase exposure, shorter lifetimes increase lockouts when mail is delayed.
  4. Bind to the requesting session. Store a nonce in the browser that asked for the link and require it when the link is opened. If the link opens on another device, ask the user to confirm on the original device or fall back to entering a code.
  5. Limit attempts. For codes, allow a handful of tries before invalidating, and rate-limit requests per address, per account and per IP. See rate shaping.
  6. Use six or more digits (or letters and digits) for codes, and compare in constant time.
  7. Never put the token in places that leak it. Avoid logging full URLs, put the token in the path or fragment as appropriate, set a strict referrer policy and avoid third-party scripts on the landing page.
  8. Show context in the email. Include the time, approximate location and device of the request, and a clear "If this was not you, ignore this message".
  9. Protect the sign-up and enumeration paths. Respond with the same message whether or not the address has an account, if your product allows it, to avoid revealing who is registered.
  10. Log and alert on unusual patterns such as many requests for different addresses from one source. See bot protection.

Corporate security gateways, antivirus tools and some mail clients fetch links in incoming mail to check them. A magic link that signs in on any GET request is consumed by the scanner before the person clicks, and the user sees "link expired". Defences:

  • Make the link open a confirmation page that requires a deliberate action (a button that sends a POST) before the token is redeemed. Scanners follow links but do not click buttons.
  • Redeem only on a POST request with a CSRF token, never on a plain GET.
  • Allow a short grace period for repeated redemption from the same browser session while still rejecting other sessions.
  • Detect common scanner user agents and IP ranges as a hint, not as a security control.
  • Offer the one-time code as a fallback in the same email, so users in strict environments can still sign in.
  • Tell users what to do when a link is "expired": request a new one and use the code.

Deliverability is part of authentication

If sign-in depends on email, the sending path is part of your login system. Treat it with the same care as a database.

RequirementPractice
Separate streamSend authentication mail from a dedicated subdomain or IP pool, apart from marketing. See IP pools
Full authenticationPass SPF, DKIM and DMARC aligned to your domain. See envelope From
Instant deliverySend immediately, with priority queues and short retry windows. See retry schedules
Minimal, stable contentShort text, one link or code, consistent subject and From name; avoid images and heavy HTML
Plain-text partInclude one for clients and filters. See plain text
Links on your domainUse your own branded link domain, not a shortener or a shared tracker; disable click tracking on authentication links
No unsubscribe footer needed for pure transactional mailFollow your legal advice; do not mix promotions into the message
MonitoringTrack delivery time (p50, p95), bounces and complaints for this stream and alert on delays. See SMTP monitoring
FallbacksOffer another sign-in method (password, passkey, SSO) so a mail outage does not lock users out

User experience details

  • After the request, show a clear waiting page: where the mail was sent, how long it can take, a resend button with a cooldown and a "change email" option. See catching email typos.
  • Put the code in the subject or first line so it appears in notifications, and use the standard one-time-code format that lets phones offer autofill.
  • Make the link open in the default browser where the user started, if possible; in-app browsers lose the session binding.
  • Handle expired and used links with a helpful message and a one-click way to request a new one.
  • Do not email the code to an address the user just typed without a typo check.
  • Provide a clear path for people who cannot receive email at all (support, alternative method).

Build checklist

ItemDone when
Token generationCryptographically random, stored hashed, single use, expires in minutes
RedemptionConfirmation step via POST, scanner-safe
Session bindingNonce or code ties the redemption to the original browser
Rate limitsPer address, account and IP; code attempt limits
Email pathDedicated stream, aligned authentication, plain-text part, no tracking
ObservabilityDelivery latency, success rate and abuse metrics on a dashboard
FallbackAnother sign-in method is available
PrivacyNo sensitive data in the email; tokens not written to logs
TestingTested with strict security gateways, in-app browsers, slow delivery and forwarded messages

Passwordless email can be both safer and friendlier than passwords, provided the email path is treated as part of the security design. Use random, short-lived, single-use tokens, bind them to the requester, protect against scanners, deliver them quickly from an authenticated, dedicated stream and give users a way in when email is slow.

Send authentication mail reliably Dedicated, authenticated sending for transactional messages.

See the email API

References and further reading

Frequently asked questions

What is a magic link?

A single-use, time-limited URL emailed to the user that signs them in without a password.

Why do magic links sometimes say expired?

Security scanners may fetch the link before the user clicks, consuming the token; use a confirmation page with a POST step.

How long should a login link or code last?

Typically ten to fifteen minutes, balancing security against delays in email delivery.

Should I use a code or a link?

Codes bind the request to the original session and suit strict environments; links are convenient on mobile. Offering both in one email is common.

What if email delivery is delayed?

Provide a resend option with a cooldown and an alternative sign-in method so users are not locked out.

Topics#passwordless#magic link#otp#authentication email#security
Was this guide helpful?Your answer helps us improve our documentation.

Start sending in minutes.

Create an account, add your domain and send your first email.

Get started Talk to sales