:

今天邮箱:00

今天邮件:00

总邮箱:0

总邮件:0

十分钟邮箱

@
收件箱
发件人 主题 回复邮箱 时间
你的邮件将在此处呈现

🧠 一、临时邮箱是怎么实现的?

1. 📩 邮件接收服务(SMTP)

临时邮箱服务商通常会搭建自己的邮件接收服务器(SMTP Server),配置多个临时域名(如 @nimail.cn)。这些域名被用于接收外部发送过来的邮件。


2. ⌛ 邮件与地址的生命周期


3. 🕸️ 前端实现


🔐 二、安全性需要注意什么?

临时邮箱虽然方便,但也有不少安全风险需要注意:

✅ 对使用者的风险

风险描述
🕵️‍♂️ 信息泄露邮件通常 不加密,任何人知道地址就能看内容。
🗑️ 内容消失邮件生命周期短,错过保存就无法找回
📛 非独占地址某些服务允许同名地址被重复使用,可能被他人读取邮件

📄 示例代码:最小可用临时邮箱 API

from flask import Flask, request, jsonify
from uuid import uuid4
import time
import threading

app = Flask(__name__)

# 存储结构:邮箱地址 -> {'created': 时间戳, 'emails': [邮件列表]}
mailboxes = {}
EXPIRY_SECONDS = 600 # 邮箱10分钟过期

def cleanup_mailboxes():
while True:
now = time.time()
expired = [addr for addr, box in mailboxes.items() if now - box['created'] > EXPIRY_SECONDS]
for addr in expired:
del mailboxes[addr]
time.sleep(60)

@app.route('/create', methods=['POST'])
def create_mailbox():
mailbox = f"{uuid4().hex[:8]}@tempmail.dev"
mailboxes[mailbox] = {'created': time.time(), 'emails': []}
return jsonify({"mailbox": mailbox})

@app.route('/send', methods=['POST'])
def send_mail():
data = request.json
to = data.get("to")
if to in mailboxes:
mailboxes[to]['emails'].append({
"from": data.get("from", "anonymous@web"),
"subject": data.get("subject", "(No Subject)"),
"body": data.get("body", ""),
"time": time.time()
})
return jsonify({"status": "sent"})
return jsonify({"error": "Mailbox not found"}), 404

@app.route('/inbox/<mailbox>', methods=['GET'])
def inbox(mailbox):
if mailbox in mailboxes:
return jsonify(mailboxes[mailbox]['emails'])
return jsonify({"error": "Mailbox not found"}), 404

if __name__ == '__main__':
threading.Thread(target=cleanup_mailboxes, daemon=True).start()
app.run(debug=True)

🚀 使用示例(Postman 或 curl)

  1. 创建邮箱
curl -X POST http://127.0.0.1:5000/create
  1. 发送邮件到临时邮箱
curl -X POST http://127.0.0.1:5000/send -H "Content-Type: application/json" -d '{
"to": "a1b2c3d4@tempmail.dev",
"from": "test@site.com",
"subject": "Hello",
"body": "This is a test message"
}'
  1. 查看收件箱
curl http://127.0.0.1:5000/inbox/a1b2c3d4@tempmail.dev