Step By Step Guide
Learn how to build your own disposable email service that lets you:
- Create instant email addresses
- Receive emails programmatically
- Protect your primary email from spam
- Manage multiple temporary addresses
What You'll Need
- A Hostinger hosting plan (Premium recommended)
- A registered domain (e.g., yourdomain.com)
- Basic Python knowledge
Step 1: Set Up Catch-All Email on Hostinger
Configure your domain to receive all emails:
1. Log in to Hostinger control panel 2. Navigate to Emails → Email Accounts 3. Create main account (e.g., catchall@yourdomain.com) 4. Go to Forwarders → Create Catch-All 5. Select your main email as recipient
Pro Tip: Use a dedicated email address (not your personal one) for the catch-all configuration.
Step 2: Email Retrieval System Setup
Python script to fetch emails using IMAP: if the code has error or bug fixed with the help of chat gpt just access imap and retrieive email based on search. and format it the way you want it.
in the next step you wil learn how to use this function and convert it an api.
import imaplib
import email
def get_emails(temp_email):
# Connect to Hostinger IMAP
mail = imaplib.IMAP4_SSL('imap.hostinger.com', 993)
mail.login('catchall@yourdomain.com', 'your_password')
# Search for target emails
mail.select('inbox')
status, data = mail.search(None, f'(TO "{temp_email}")')
emails = []
for email_id in data[0].split():
# Process each email
status, msg_data = mail.fetch(email_id, '(RFC822)')
raw_email = msg_data[0][1]
msg = email.message_from_bytes(raw_email)
# Extract email components
email_info = {
'subject': msg['subject'],
'from': msg['from'],
'body': get_email_body(msg)
}
emails.append(email_info)
return emails
Step 3: Create Web Endpoints
FastAPI endpoints for email management:
from fastapi import FastAPI
import uuid
app = FastAPI()
//domain.com/new-email it will return new random email address
@app.get("/new-email")
def generate_email():
"""Create random email address"""
return {
"email": f"{uuid.uuid4().hex[:8]}@yourdomain.com",
"inbox_url": "/inbox/{email}"
}
//domain.com/inbox/emailhere and it will return all the email
@app.get("/inbox/{email}")
def get_inbox(email: str):
"""Retrieve messages for specific email"""
return {
"email": email,
"messages": get_emails(email)
}
Security Considerations
- 🔒 Always use environment variables for credentials
- 🚫 Never expose your admin email publicly
- ⏲️ Implement automatic email expiration
- ⏲️ delete old email in 60 minutes.
- 📉 Add rate limiting to your API endpoints
- always secure your api endpoint with api key or with token
Next Steps
You now have a functional temporary email system! To enhance it:
- Add web interface with HTML templates
- Implement email content filtering
- Set up automatic cleanup cron job
- Add SMTP support for sending emails if needed but not necessary if you only want to receive email and not sending it
Remember: This system uses Hostinger's IMAP servers. Check their terms of service for usage limits.