Testing Twilio Verify Email OTP: A Developer Guide
Testing Twilio Verify Email OTP: A Developer Guide
Twilio Verify can send one-time codes by email through a SendGrid account that you connect. Test it with addresses you control; a temporary inbox is fine for one manual look, but on a Twilio trial email goes only to your sign-up address.
What you need to set up
Twilio's Verify email guide lists the parts:
- A Twilio SendGrid account and an API key with limited scopes.
- A verified sender, better an authenticated domain. Without it, recipients see "via sendgrid.net".
- A dynamic template in SendGrid that contains the code variable, for example
{{twilio_code}}. Its ID starts withd-. - An email integration in Verify that joins key, template and sender, assigned to your Verify service.
Each of these is a place where a test can fail before any mail is sent.
Limits that surprise testers
| Limit | Source |
|---|---|
| On a trial, email is restricted to the address you signed up with | Twilio trial docs |
| Trials last 30 days and include 40 verifications and 3,000 emails | Same page |
| Custom content and custom code templates aren't available in the trial | Same page |
| The verification SID is deleted once approved, expired after 10 minutes, or out of attempts | Verification Check API |
| Checking a deleted verification gives a 404 | Same page. Treat it as "expired", not as a server error |
The first line decides your approach: with a trial you can't send codes to a throwaway address at all, unless you signed up with it. For an account, that is a bad idea. Why.
Starting a verification
curl -X POST "https://verify.twilio.com/v2/Services/$SERVICE_SID/Verifications" \
--data-urlencode "[email protected]" \
--data-urlencode "Channel=email" \
-u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN"
Checking the code:
curl -X POST "https://verify.twilio.com/v2/Services/$SERVICE_SID/VerificationCheck" \
--data-urlencode "[email protected]" \
--data-urlencode "Code=123456" \
-u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN"
Test plan
Automated, on every build. Don't call Twilio. Replace it with a stub that answers "pending", "approved", "max_attempts_reached" and 404. You test your own screens and messages quickly and for free.
Automated, once a day. One real round trip on an upgraded account. Send to a catch-all such as verify-{time}@qa.yourdomain, read it by IMAP, and check the code. That exercises key, template, sender and domain.
By hand, before a release.
- Send to your own mailboxes at two or three large providers. Look at sender, subject, spam folder and phone preview.
- With an upgraded account, send one to a temporary inbox from MTempMail to see the mail without any personal filters. Use a test user with no real data, as the inbox has no password.
- Enter a wrong code, an old code, and a right code twice.
- Wait eleven minutes and try the first code.
- Request two codes and note which one is accepted.
What not to test this way: delivery at scale. Sending many codes to disposable domains tells you little and can hurt your sender reputation.
Reading errors
- No mail, status pending: look in SendGrid's activity for a drop or bounce. A wrong template ID or unverified sender is the first suspect.
- Mail without a code: the template lacks the variable.
- 404 on check: expired, already approved, or a different
Tospelling. Use the same form of the address in both calls, including letter case. - Mail in spam: authenticate the domain. A single verified sender isn't enough for volume.
Common questions
Does Verify need SendGrid for email?
Yes, according to Twilio's guide the email channel uses your SendGrid account.
Can MTempMail's API read the code for me?
Not at the moment. It is off. See other inboxes for tests.
Can I test SendGrid without sending?
There is a sandbox mode for that. How it works.
Tags:
Related guides
- Temp Mail for Twilio: Sign-Up, Verification and the Trial
- Temp Mail for SendGrid (Twilio Email API): What to Test
- Twilio Free Trial with Temp Mail: What Actually Works (and the Phone Catch)
- CapCut Code Not Arriving on Temp Mail: Causes and the Safe Fix
- Temp Mail for Kick: The 60-Day Email Lock and Other Limits