प्रोग्रामेटिक रूप से ईमेल एड्रेस बनाना तब तक आसान लगता है जब तक आप पूरे loop को automate करने की कोशिश नहीं करते: एक address generate करें, एक email trigger करें (OTP, magic link, invite), फिर उस email को code में reliably पढ़ें बिना brittle parsing या inbox collisions के।
AI agents और QA automation के लिए, “create email address” वास्तव में कुछ अधिक specific चीज़ का shorthand है:
- On demand routable inbox provision करना (human mailbox नहीं)।
- Messages को deterministically receive करना (webhook या polling, “sleep 10 seconds” नहीं)।
- Content को structured data (JSON) के रूप में consume करना ताकि tools और agents safely act कर सकें।
यह गाइड मुख्य approaches, प्रत्येक कब काम करता है, और एक व्यावहारिक implementation pattern explain करता है जिसे आप agent toolchains और test harnesses में डाल सकते हैं।
“प्रोग्रामेटिक रूप से ईमेल एड्रेस बनाना” का मतलब क्या है
Consumer email में, एक “email address” आमतौर पर credentials, UI access, recovery options, और ongoing identity के साथ long-lived account को imply करता है। Automation में, वह model अक्सर गलत abstraction है।
आप आमतौर पर जो चाहते हैं वह एक inbox handle है जिसे आप create और destroy कर सकें, plus एक address जो इसमें route करे। वह inbox एक single run, test, या agent session में messages के लिए scoped container बन जाता है।
यह distinction क्यों मायने रखता है:
- Isolation: प्रति run एक inbox collisions से बचाता है।
- Lifecycle control: आप inboxes को expire और discard कर सकते हैं।
- Least privilege: automation केवल वही पढ़ता है जिसकी जरूरत है, कम समय के लिए।
यदि आप अपने test harness के लिए API या internal interface design कर रहे हैं, तो पहले inbox resource को model करें, फिर उसमें address attach करें।
अपने goal के आधार पर सही method चुनें
Email addresses generate या simulate करने के कई तरीके हैं। Best option इस बात पर depends करता है कि क्या आपको actually mail receive करने की जरूरत है, और क्या system under test को real email infrastructure पर deliver करना होगा।
Quick comparison
| Method | Can receive real emails? | Good for CI and agents? | Typical failure mode | Best use case |
|---|---|---|---|---|
| Reserved domains (example.com) | नहीं | हाँ | No inbox exists | Unit tests, validation-only flows |
| Plus-addressing (name+tag@) | हाँ (if provider supports it) | कभी-कभी | Collisions, provider quirks | Lightweight tagging in a real inbox |
| Provider aliases (Workspace, etc.) | हाँ | कभी-कभी | Setup overhead, limits | Small teams, stable staging identity |
| Catch-all domain | हाँ | Risky | Misrouting, noisy inbox | Controlled environments with strict routing |
| Local SMTP capture | नहीं (not real delivery) | हाँ | Not representative of prod | Dev and local integration tests |
| Disposable inbox API | हाँ | हाँ | Vendor dependency | Deterministic E2E tests, agent workflows |
यदि आपके workflow को “email was delivered” validate करना है और फिर OTP/link extract करना है, तो disposable inboxes (API के via create किए गए) अक्सर सबसे automation-friendly choice हैं।

एक व्यावहारिक, repeatable workflow (tests और AI agents के लिए काम करता है)
Backend के बावजूद, robust email automation समान पांच steps follow करता है:
1) Inbox provision करें (और address पाएं)
आप एक function चाहते हैं जो return करे:
-
address(email address जो आप form में type कर सकते हैं) -
inbox_id(handle जिसका उपयोग आप messages query या correlate करने के लिए करते हैं) - metadata जैसे expiry, if supported
inbox_id को अपने system में primary key के रूप में treat करें।
2) Email trigger करें
यह आपका normal application behavior है: signup, passwordless sign-in, invite, email verification, etc.
Reliability के लिए, जब आप कर सकें तो correlation add करें। दो common strategies:
-
User identifier में
run_idडालें (उदाहरण के लिए, email का local part)। - Email content या headers में application-level correlation ID add करें (यदि आप sending control करते हैं)।
3) Deterministically wait करें (webhook-first, polling fallback)
Fixed sleeps से बचें। Deterministic wait ऐसा दिखता है:
- Hard timeout के साथ timer start करें।
- Available होने पर webhook delivery को prefer करें।
- Backoff के साथ polling पर fall back करें।
यह tests को fast रखता है जब email जल्दी arrive करती है और फिर भी stable रहता है जब delivery slow होती है।
4) Data के रूप में parse करें, केवल जो चाहिए extract करें
आपकी automation को आमतौर पर एक artifact चाहिए:
- एक OTP code
- एक magic link URL
- एक invite token
इसे stable representation से extract करें। यदि आप content को LLM agent में feed कर रहे हैं, तो raw HTML के बजाय minimal JSON envelope (sender, subject, text body, extracted links/codes) provide करें।
5) Clean up करें
Short retention risk और cost reduce करता है:
- Inboxes को aggressively expire करें
- Full message bodies log करने से बचें
- Raw email को केवल debugging के समय रखें
Common pitfalls (और इनसे कैसे बचें)
Pitfall: “मैंने address बनाया, लेकिन सही email reliably नहीं पढ़ सकता”
यह shared inboxes और plus-addressing patterns के साथ होता है। Multiple runs same mailbox में write करते हैं, फिर आपके code को eventually consistent pile में “search” या “filter” करना पड़ता है।
Fix: प्रति run एक inbox create करें (या per test) और केवल उस inbox को query करें।
Pitfall: HTML scraping आपकी automation break कर देती है
Email HTML templates, clients, और यहाँ तक कि A/B tests के across vary करता है। इसे regex के साथ parse करना fragile है।
Fix: text/plain या normalized JSON output को prefer करें। यदि आपको HTML parse करना है, तो sanitize करें और extraction logic को conservative रखें।
Pitfall: webhooks security hole बन जाते हैं
Inbound email untrusted input है, और webhook endpoints अक्सर public होते हैं।
Fix:
- Available होने पर signed payloads verify करें
- Replay risk reduce करने के लिए timestamp tolerances enforce करें
- Extracted URLs को अपने domains की allowlist से match करते हैं validate करें
Implementation pattern: एक “EmailAddressFactory” interface
यदि आप multiple environments (local dev, CI, staging) support करते हैं, तो small interface define करें और implementations swap करें।
Minimal contract:
createInbox(): { inbox_id, address }waitForMessage(inbox_id, matcher, timeout_ms): messageextractVerificationArtifact(message): { otp?, url? }
यह interface आपके agent tools और tests को stable रखता है भले ही आप providers change करें।
Programmatic email के लिए disposable inbox API (Mailhook) का उपयोग
Mailhook programmable, disposable inboxes के around बनाया गया है जो received emails को structured JSON के रूप में deliver करते हैं, webhook notifications और polling API के साथ।
Actual product contract से drift न करने के लिए, यहाँ Mailhook का canonical integration reference use करें: llms.txt।
High-level flow
- API के via disposable inbox create करें।
- Returned address को अपने app flow में use करें।
- Email को JSON के रूप में webhook (recommended) या poll के via receive करें।
- अपना artifact (OTP या link) extract करें।
Pseudocode example (agent-friendly)
Exact endpoints और schema llms.txt में defined हैं। नीचे pattern control flow पर focus करता है।
// Pseudocode (Node-style)
async function createEmailAddressForRun(runId) {
// Call Mailhook to create a disposable inbox
// Returns { inbox_id, address, ... }
const inbox = await mailhook.createInbox({
metadata: { run_id: runId },
// optionally configure webhook target depending on your architecture
});
return { inbox_id: inbox.inbox_id, address: inbox.address };
}
async function waitForVerificationEmail(inbox_id, timeoutMs) {
// Webhook-first: in many setups you would push webhook events to a queue,
// then your agent/test waits on that queue.
// Polling fallback: query inbox messages until matcher hits or timeout.
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
const messages = await mailhook.listMessages({ inbox_id });
const match = messages.find(m =>
(m.subject || "").toLowerCase().includes("verify")
);
if (match) return match;
await sleep(500); // small backoff; increase gradually in real code
}
throw new Error("Timed out waiting for verification email");
}
function extractArtifact(message) {
// Prefer a normalized field or text/plain representation when provided.
// Keep extraction minimal and deterministic.
return {
otp: maybeExtractOtp(message),
url: maybeExtractFirstAllowedUrl(message, ["https://yourapp.example"])
};
}
Webhook verification (इसे skip न करें)
Mailhook security के लिए signed payloads support करता है। अपने webhook handler में signature verification को default बनाएं, और verification fail होने पर fail closed करें।
क्योंकि signature formats provider के अनुसार differ करते हैं और change हो सकते हैं, exact headers और verification steps के लिए llms.txt refer करें।
Shared domains vs custom domains
जब आप प्रोग्रामेटिक रूप से email address create करते हैं, तो आपको domain strategy की भी जरूरत होती है:
- Shared domains start करने के लिए fast हैं और ephemeral flows के लिए great हैं।
- Custom domains tighter control और brand alignment में help करते हैं, और useful हो सकते हैं जब आपको consistent sending reputations या stricter routing चाहिए।
Mailhook shared domains और custom domain support दोनों को support करता है, जो आपको environment के अनुसार right posture pick करने देता है।
Batch processing: जब एक inbox काफी नहीं है
Agent systems और CI pipelines अक्सर parallel में run करते हैं। उन cases में, आप एक साथ many inboxes provision करना चाहते हैं और messages को batches में process करना चाहते हैं।
Mailhook batch email processing support करता है, जो useful है जब:
- आप concurrently many signups launch करते हैं
- आप large test matrices run करते हैं
- आपको efficiently inboxes के set के लिए messages drain करने की जरूरत है
(Again, precise API contract के लिए llms.txt देखें।)
“Create email address” automation के लिए reliability checklist
इसे final pre-flight के रूप में use करें इससे पहले कि आप अपने provider या अपने mail templates को blame करें:
- Collisions से बचने के लिए प्रति run एक inbox (या per test) use करें।
- Webhook-first को prefer करें, resilience के लिए polling fallback रखें।
- Explicit timeouts use करें और उन्हें structured events के रूप में log करें।
- Full HTML नहीं, intent (sender/subject/expected artifact) पर assert करें।
- Email को untrusted input के रूप में treat करें, especially LLM agents के साथ।
- Available होने पर signed webhooks verify करें।
- Retention minimize करें और logs में sensitive fields redact करें।
यदि आप related reliability topics पर deeper dives चाहते हैं, तो ये Mailhook posts अच्छे companions हैं:
- Create email on demand for end-to-end test suites
- Email inbox design: webhooks, polling, and storage
- Open an email programmatically: from raw to JSON
अक्सर पूछे जाने वाले प्रश्न
क्या मैं प्रोग्रामेटिक रूप से real Gmail address बना सकता हूँ? Consumer Gmail accounts को automatically create करना automation के लिए reliable या recommended approach नहीं है। Tests और agents के लिए, disposable inboxes provision करना या controlled domains और inbox APIs use करना better है।
Plus-addressing और नया inbox create करने के बीच क्या अंतर है? Plus-addressing कई address variants create करता है जो typically same mailbox में route करते हैं, जो parallel runs में collisions cause कर सकते हैं। एक नया disposable inbox isolation और simpler matching provide करता है।
मुझे emails receive करने के लिए webhooks या polling use करना चाहिए? Webhooks आमतौर पर faster और अधिक efficient होते हैं क्योंकि delivery event-driven है। Polling अभी भी fallback के रूप में useful है जब webhooks unavailable हों या temporarily fail हो रहे हों।
मैं email-based tests को non-flaky कैसे बनाऊं? प्रति test run एक inbox use करें, fixed sleeps से बचें, hard timeouts set करें, और HTML scrape करने के बजाय messages को structured data (या text/plain) के रूप में parse करें।
क्या LLM agent को inbound emails पढ़ने देना safe है? यह हो सकता है, यदि आप email को untrusted input के रूप में treat करें, model को minimal JSON envelope pass करें, content sanitize करें, और act करने से पहले कोई भी extracted URLs या codes validate करें।
Programmable temp inboxes के लिए Mailhook try करें
यदि आपका goal AI agents, QA automation, या verification flows के लिए प्रोग्रामेटिक रूप से email address create करना है, तो Mailhook API के via disposable inbox creation, structured JSON email output, real-time webhooks (signed payloads के साथ), और polling API provide करता है।