## TL;DR

Poll the inbox for the newest message from the signup site, extract the code with a regex tuned to that site's format, and submit it within the expiry window, usually 10 to 15 minutes. Retry the poll a few times before requesting a resend, because requesting too many codes invalidates the earlier ones. The whole loop is: poll, extract, submit, confirm.

```text
handling email verification codes programmatically
```

## Use this when

- Your signup script needs to complete email code verification
- You are automating account creation across many sites
- Verification codes keep expiring before your script submits them

## Not for this skill when

- You are trying to verify an address you dont control
- The site uses app-based or SMS codes you cant receive
- You want to skip verification entirely

## Steps

1. Trigger the code, then poll. Request the code from the site, then check the inbox every 10 to 15 seconds for up to 5 minutes. Expected: the verification email arrives within a minute or two.
2. Match the right message. Filter by sender domain and subject keywords, and take the newest match after the request timestamp. Expected: you grab this signup's code, not an old one.
3. Extract the code. Use a regex for the site's format, usually 4 to 8 digits; test it against a sample email first. Expected: a clean code string, no surrounding text.
4. Submit fast. Send the code back to the site immediately; most expire in 10 to 15 minutes. Expected: verification accepted on the first try.
5. Handle expiry gracefully. If the submit fails as expired, request one new code and repeat the loop once. Expected: success on the second attempt.
6. Log the outcome per site. Note the code format, expiry, and any quirks in your venue notes. Expected: the next signup on that site needs no debugging.

## Variant phrasings

### automating OTP email verification

Same loop: poll, filter by sender, regex the code, submit within expiry.

### how to read verification codes from email in a script

IMAP or provider API for fetching, regex for extraction; keep the poll window short.

### email code expired before submitting

Submit faster, poll more often, and dont request a second code until the first is confirmed dead.

## Why it happens

Verification codes exist to prove a human controls the inbox, but the mechanism is just an email with a number in it. Anything that can read the inbox and type the number can complete the loop; the failure modes are all timing and message-matching, not security.

## Edge cases

- Some sites send the code as an image or require clicking a magic link instead; detect which one before writing the extractor.
- Multiple pending codes: always use the newest, and know that requesting a new one usually kills the old ones.
- Codes in non-English emails need locale-aware subject matching; match the sender domain instead.
- Never log full codes alongside the account credentials in the same file; keep verification logs separate.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_oEESkWBw2DuuhjSbdm1VOQ
