Skip to content

Security

Magic link email template.

A passwordless sign-in link that is single-use, expires quickly and says who asked.

Look

SubjectYour sign-in link for Acme

PreviewUse this link to sign in. It works once.

The preview uses example data, so no real names or numbers. Mail programs differ: send one to your own inbox before you rely on it.

When to send it

When someone chooses to sign in by email instead of a password. The email is the credential, so keep it short and time-limited.

Get it right

  • Make the link single-use and short-lived; 10 to 15 minutes is typical.
  • Some mail systems open links to scan them, which can use up a single-use link before the person clicks. Have the link open a page with a Continue button, and complete the sign-in when that button is pressed.
  • Mention the device that asked, so an unexpected email stands out.
  • Offer a code as a second route if people often open the email on a different device from the one they are signing in on.

Use it in Mailtruss

Choose New template, pick Magic sign-in link, change the words and colours, and publish. 3,000 emails a month are free, with no credit card.

Variables

Wrap a name in double braces and Mailtruss fills it in when you send. A value after a bar is the fallback when you leave it out, such as {{first_name | there}}. Values are escaped, so a name with markup in it cannot break the message.

VariableWhat it isExampleNeeded?
app_nameYour product or company name.AcmeYes
magic_urlThe one-time sign-in link.https://app.example.com/magic?token=e90b21Yes
expires_inHow long the link works, in words. Optional.10 minutesOptional
deviceThe browser and system that asked for the link. Optional.Safari on iPhoneOptional
footer_textThe small print at the bottom, such as your company name and postal address. Optional: a short note about why the person got this email is used when you leave it out.Acme Inc, 1 Main Street, SpringfieldOptional

Create it and send it

Create the template from this starter with one request (or from the dashboard), then send it by its alias with your values. Only the published version is ever sent. Other languages are on send email by language.

Create the template
curl -X POST https://mailtruss.com/api/v1/templates \
-H "Authorization: Bearer $MAILTRUSS_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "starter": "magic-link", "look": "midnight", "alias": "magic-link", "publish": true }'
send.ts
import { MailClient } from "mailtruss";
​
const mail = new MailClient({ apiKey: process.env.MAILTRUSS_API_KEY! });
​
await mail.emails.send(
{
from: "Acme <hello@yourdomain.com>",
to: "person@example.com",
template: {
id: "magic-link", // the alias you gave the template
variables: {
app_name: "Acme",
magic_url: "https://app.example.com/magic?token=e90b21",
},
},
},
{ idempotencyKey: "magic-link-<your-event-id>" }, // makes retries safe
);

The HTML and the text

This is exactly what the starter produces. Copy it into any system that sends HTML, or use it in Mailtruss to keep editing visually.

magic-link.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="color-scheme" content="light">
<meta name="supported-color-schemes" content="light">
<style>@media only screen and (max-width:520px){.mt-card{width:100%!important;border-radius:0!important}.mt-px{padding-left:22px!important;padding-right:22px!important}.mt-col{display:block!important;width:100%!important;padding:0 0 18px 0!important}.mt-hero,.mt-section{padding:24px 20px!important}.mt-title{font-size:26px!important}}</style>
</head>
<body class="mt-page" style="margin:0;padding:0;background:#0b0b10">
<div style="display:none;max-height:0;overflow:hidden;opacity:0;color:transparent;mso-hide:all">Use this link to sign in. It works once.&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;</div>
<table class="mt-pagebg" role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background:#0b0b10">
<tr>
<td align="center" style="padding:32px 12px">
<table class="mt-card" role="presentation" width="600" cellpadding="0" cellspacing="0" style="width:100%;max-width:600px;background:#15151d;border-radius:16px;border:1px solid #26262f;border-collapse:separate">
<tr>
<td style="height:34px;line-height:1px;font-size:1px">&nbsp;</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 40px 22px">
<table role="presentation" cellpadding="0" cellspacing="0" border="0" >
<tr>
<td style="padding:0 10px 0 0;vertical-align:middle">
<table role="presentation" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="mt-mark" width="30" height="30" align="center" valign="middle" style="width:30px;height:30px;background:#8b7bff;border-radius:11px">
<table role="presentation" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="mt-markdot" width="10" height="10" style="width:10px;height:10px;line-height:10px;font-size:1px;background:#111214;border-radius:50%">&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td class="mt-brandtext" style="vertical-align:middle;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:17px;font-weight:700;letter-spacing:-0.2px;color:#8b7bff">{{app_name | Your app}}</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 40px 18px">
<div class="mt-eyebrow" style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:12px;font-weight:700;letter-spacing:1.4px;text-transform:uppercase;color:#8b7bff;margin:0 0 12px">Magic link</div>
<h1 class="mt-title" style="margin:0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:30px;font-weight:650;line-height:116%;letter-spacing:-0.8px;text-decoration:none;color:#ececf3;text-align:left">Sign in to {{app_name | your account}}</h1>
<p class="mt-text" style="margin:12px 0 0;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:16px;font-weight:400;line-height:165%;letter-spacing:0px;text-decoration:none;color:#818188;text-align:left">Press the button to sign in. You do not need a password.</p>
</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 40px 20px">
<table role="presentation" cellpadding="0" cellspacing="0" border="0" width="100%" style="border-collapse:separate;width:100%;">
<tr>
<td class="mt-btncell" align="center" bgcolor="#8b7bff" style="background:#8b7bff;border-radius:10px;">
<a class="mt-button" href="{{magic_url}}" style="display:block;padding:14px 26px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:15px;font-weight:600;line-height:100%;letter-spacing:0px;color:#0b0b10;text-decoration:none;text-align:center;border-radius:10px">Sign in</a>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 40px 0px">
<p class="mt-text mt-small" style="margin:0 0 14px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:13px;font-weight:400;line-height:165%;letter-spacing:0px;text-decoration:none;color:#818188;text-align:left">This link works for {{expires_in | 10 minutes}} and can be used once.</p>
</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 40px 18px">
<div class="mt-linkbox" style="background:#282541;border-radius:10px;padding:13px 16px">
<div class="mt-label" style="margin:0 0 5px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:12px;line-height:150%;color:#818188">Or paste this link into your browser</div>
<a class="mt-link" href="{{magic_url}}" style="font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace;font-size:12px;line-height:150%;color:#a99dff;text-decoration:none;word-break:break-all">{{magic_url}}</a>
</div>
</td>
</tr>
{{#if device}}
<tr>
<td class="mt-px" style="padding:0px 40px 0px">
<p class="mt-text mt-small" style="margin:0 0 14px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:13px;font-weight:400;line-height:165%;letter-spacing:0px;text-decoration:none;color:#818188;text-align:left">Asked for from {{device}}.</p>
</td>
</tr>
{{/if}}
<tr>
<td class="mt-px" style="padding:0px 40px 18px">
<div class="mt-callout mt-co-warning" style="background:#35291d;border-left:4px solid #b7791f;border-radius:8px;padding:15px 18px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:14px;line-height:155%;color:#e9d7bc">
<p style="margin:0">If you did not try to sign in, you can ignore this email. No one can sign in without this link.</p>
</div>
</td>
</tr>
<tr>
<td class="mt-px" style="padding:14px 40px 0">
<div class="mt-rule" style="border-top:1px solid #404048;line-height:0;font-size:0;height:0">&nbsp;</div>
</td>
</tr>
<tr>
<td class="mt-px mt-footer" style="padding:16px 40px 34px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;font-size:12px;line-height:165%;color:#818188">{{footer_text | You are receiving this email because of your account.}}</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Plain text
{{app_name | Your app}}
​
Magic link
Sign in to {{app_name | your account}}
Press the button to sign in. You do not need a password.
​
Sign in: {{magic_url}}
​
This link works for {{expires_in | 10 minutes}} and can be used once.
​
Or paste this link into your browser
{{magic_url}}
​
{{#if device}}Asked for from {{device}}.{{/if}}
​
If you did not try to sign in, you can ignore this email. No one can sign in without this link.
​
{{footer_text | You are receiving this email because of your account.}}

More templates

All email templates