Password reset and one-time code emails that arrive in seconds
A sign-in code that arrives two minutes late, or in spam, is a locked-out customer. These are the most time-sensitive emails your system sends, and the ones that most need a trusted domain.
What makes these emails reach the inbox
- A verified domain with DKIM: receivers trust signed mail from your own domain. See domain verification.
- Short, plain content: a code or a link, your name, and nothing that looks like advertising.
- Both text and HTML: a plain-text version helps filters and is easy to read on any phone.
- A clean sending record: bounced and complaining addresses are suppressed automatically so your reputation stays good.
Example: send a one-time code
const code = String(crypto.randomInt(100000, 1000000));
// store a hash of the code with a short expiry in your database first
const r = await fetch("https://api.jmsurfmail.co.ke/api/v1/emails", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.JMSURF_MAIL_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
from: "YourApp <[email protected]>",
to: user.email,
subject: `${code} is your YourApp sign-in code`,
text: `Your sign-in code is ${code}. It expires in 10 minutes. If you did not ask for it, ignore this email.`,
tags: ["otp"],
}),
});
if (!r.ok) throw new Error((await r.json()).error);Use a send-only key in the service that sends codes. It can send but cannot read your logs or change domains, which limits the damage if that service is ever compromised.
Password reset links
- Create a random token, store only its hash with an expiry of 30 to 60 minutes, and email a link containing the token.
- Use a template (for example
password-reset) with{{name}}and{{link}}so the wording is managed in one place. See templates. - Never put the user's password or full account details in the email.
- Do not use an Idempotency-Key that stays the same across separate reset requests; each request should send a new link.
Add an SMS copy for important codes
For high-value accounts, add an sms object to the same request and the code also goes by SMS through your JMSURF SMS account. If the email address bounces, your webhook tells you and you can rely on SMS next time. See email and SMS.
Handle errors properly
| Response | What to do |
|---|---|
| 200 with status sent | Show "We sent a code to …". |
| 403 domain_not_verified | Configuration problem on your side: check the From domain. |
| 429 quota_exceeded | Your allowance is used up; upgrade the plan. Consider SMS as the fallback meanwhile. |
| 429 rate_limited | More than 20 requests a second on this key; retry after a moment. |
| 502 send_failed | Show a friendly error and let the user try again. |
Questions
- How fast do codes arrive?
- Emails are handed to the delivery network as soon as the API call is made; most arrive within seconds. The log shows when each one was delivered.
- Should OTP emails be tracked?
- Open and click tracking is optional in Settings. Many teams leave it off for security emails.
Send your first email today
Free plan with 100 emails a month, no card needed. Questions? WhatsApp or call +254 712 504 593, or email [email protected].