Skip to content

Security

One-time code (OTP) email template.

A short numeric code in large type, with the expiry and a warning not to share it.

Look

Subject482 913 is your Acme code

Preview482 913 is your code. It expires in 10 minutes.

Shown inApple Mail and iPhone Mail switch automatically

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

For two-step sign-in, confirming a sensitive action, or verifying an address with a code instead of a link. It is read in seconds, often from a notification, so the code has to be unmissable.

Get it right

  • Put the code in the subject as well, so it shows in a phone notification without opening the email.
  • Use six digits, expire them within about 10 minutes, accept each only once, and limit the number of attempts.
  • Say plainly that the code must never be shared. A common scam is to talk someone into reading a code out.
  • Send it as fast as you can; a code that arrives after it expires is worse than no code.

Use it in Mailtruss

Choose New template, pick One-time code, 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
codeThe code to type in. Generate it on your server.482 913Yes
expires_inHow long the code works, in words. Optional.10 minutesOptional
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": "one-time-code", "look": "console", "alias": "one-time-code", "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: "one-time-code", // the alias you gave the template
variables: {
app_name: "Acme",
code: "482 913",
},
},
},
{ idempotencyKey: "one-time-code-<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.

one-time-code.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 dark">
<meta name="supported-color-schemes" content="light dark">
<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}}@media (prefers-color-scheme:dark){.mt-pagebg,.mt-page{background:#0e0f12!important}.mt-card{background:#17181c!important;border-color:#2b2d34!important}.mt-title,.mt-subtitle,.mt-heading,.mt-value,.mt-quote{color:#f1f1f4!important}.mt-text,.mt-li,.mt-list{color:#cfd0d8!important}.mt-label,.mt-small,.mt-footer,.mt-unsub,.mt-footer a{color:#9b9da8!important}.mt-rule{border-color:#2b2d34!important}.mt-tone-tint,.mt-tone-card{background:#21232a!important;border-color:#2b2d34!important}.mt-tone-tint .mt-title,.mt-tone-card .mt-title{color:#f1f1f4!important}.mt-code,.mt-codeblock,.mt-linkbox{background:#111216!important;color:#f1f1f4!important}.mt-inline-code{background:#21232a!important;color:#f1f1f4!important}.mt-link{color:#339575!important}.mt-brandtext{color:#339575!important}.mt-btncell{background:#007a52!important;border-color:#007a52!important}.mt-button{color:#ffffff!important}.mt-ghost{background:transparent!important;border-color:#339575!important}.mt-ghost .mt-button{color:#339575!important}.mt-badge-neutral{background:#21232a!important;color:#f1f1f4!important}.mt-mark,.mt-stepnum{background:#007a52!important;color:#ffffff!important}.mt-markdot{background:#ffffff!important}.mt-tone-accent,.mt-tone-dark{border:1px solid #2b2d34!important}.mt-co-info{background:#1f2b44!important;color:#c8d7f3!important}.mt-co-success{background:#192f23!important;color:#c0dbc8!important}.mt-co-warning{background:#3a2d1d!important;color:#ebd9c0!important}.mt-co-danger{background:#3c1e1f!important;color:#edc6c4!important}}</style>
</head>
<body class="mt-page" style="margin:0;padding:0;background:#eef0ee">
<div style="display:none;max-height:0;overflow:hidden;opacity:0;color:transparent;mso-hide:all">{{code}} is your code. It expires in {{expires_in | 10 minutes}}.&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:#eef0ee">
<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:#fbfcfb;border-radius:6px;border:1px solid #cfd6d1;border-collapse:separate">
<tr>
<td style="height:31px;line-height:1px;font-size:1px">&nbsp;</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 36px 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:#007a52;border-radius:6px">
<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:#ffffff;border-radius:50%">&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td class="mt-brandtext" style="vertical-align:middle;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace;font-size:17px;font-weight:700;letter-spacing:-0.2px;color:#007a52">{{app_name | Your app}}</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 36px 8px">
<h1 class="mt-title" style="margin:0;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace;font-size:24px;font-weight:700;line-height:125%;letter-spacing:-0.5px;text-decoration:none;color:#17201b;text-align:left">Your verification code</h1>
</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 36px 0px">
<p class="mt-text" style="margin:0 0 14px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace;font-size:14px;font-weight:400;line-height:170%;letter-spacing:0px;text-decoration:none;color:#33403a;text-align:left">Enter this code to continue. It expires in {{expires_in | 10 minutes}}.</p>
</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 36px 18px">
<div class="mt-code" style="background:#f0f1f0;border-radius:8px;padding:20px 12px;text-align:center;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace;font-size:32px;font-weight:700;line-height:120%;letter-spacing:9px;color:#17201b">{{code}}</div>
</td>
</tr>
<tr>
<td style="height:4px;line-height:1px;font-size:1px">&nbsp;</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 36px 18px">
<div class="mt-callout mt-co-danger" style="background:#fdf0ee;border-left:4px solid #c0352b;border-radius:6px;padding:15px 18px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace;font-size:14px;line-height:155%;color:#6a1a14">
<p style="margin:0 0 4px;font-weight:700">Keep it private</p>
<p style="margin:0">Never share this code with anyone, including people who say they work for {{app_name | us}}. We will never ask you for it.</p>
</div>
</td>
</tr>
<tr>
<td class="mt-px" style="padding:0px 36px 0px">
<p class="mt-text mt-small" style="margin:0 0 14px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace;font-size:13px;font-weight:400;line-height:170%;letter-spacing:0px;text-decoration:none;color:#6e7470;text-align:left">If you did not ask for a code, you can ignore this email.</p>
</td>
</tr>
<tr>
<td class="mt-px" style="padding:14px 36px 0">
<div class="mt-rule" style="border-top:1px solid #e2e4e2;line-height:0;font-size:0;height:0">&nbsp;</div>
</td>
</tr>
<tr>
<td class="mt-px mt-footer" style="padding:16px 36px 31px;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,'Liberation Mono',monospace;font-size:12px;line-height:165%;color:#6e7470">{{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}}
​
Your verification code
​
Enter this code to continue. It expires in {{expires_in | 10 minutes}}.
​
{{code}}
​
Keep it private
Never share this code with anyone, including people who say they work for {{app_name | us}}. We will never ask you for it.
​
If you did not ask for a code, you can ignore this email.
​
{{footer_text | You are receiving this email because of your account.}}

More templates

All email templates